removing maven resources plugin dependency from SDK (#1193)

* removing maven resources plugin dependency from SDK

Signed-off-by: salaboy <Salaboy@gmail.com>

* Update pom.xml

Signed-off-by: salaboy <Salaboy@gmail.com>

* adding maven resources plugin as a plugin

Signed-off-by: salaboy <Salaboy@gmail.com>

* Self-validate presence of sdk_version.

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

---------

Signed-off-by: salaboy <Salaboy@gmail.com>
Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Co-authored-by: Artur Souza <asouza.pro@gmail.com>
This commit is contained in:
salaboy 2025-01-19 02:15:21 +00:00 committed by GitHub
parent 9cd6db2f5d
commit 0fafc97229
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 13 deletions

View File

@ -24,6 +24,7 @@
<maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version> <maven-dependency-plugin.version>3.1.1</maven-dependency-plugin.version>
<maven-antrun-plugin.version>1.8</maven-antrun-plugin.version> <maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
<maven-deploy-plugin.version>2.7</maven-deploy-plugin.version> <maven-deploy-plugin.version>2.7</maven-deploy-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version> <maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>11</maven.compiler.target>
@ -156,6 +157,11 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>

View File

@ -21,6 +21,7 @@
<argLine> <argLine>
--add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED
</argLine> </argLine>
</properties> </properties>
<dependencies> <dependencies>
@ -28,12 +29,6 @@
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<type>maven-plugin</type>
</dependency>
<dependency> <dependency>
<groupId>io.dapr</groupId> <groupId>io.dapr</groupId>
<artifactId>dapr-sdk-autogen</artifactId> <artifactId>dapr-sdk-autogen</artifactId>
@ -169,6 +164,10 @@
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>

View File

@ -16,10 +16,11 @@ package io.dapr.utils;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
public final class Version { public final class Version {
private static String sdkVersion = null; private static volatile AtomicReference<String> sdkVersion = new AtomicReference<>();
/** /**
* Retrieves sdk version from resources. * Retrieves sdk version from resources.
@ -27,20 +28,31 @@ public final class Version {
* @return String version of sdk. * @return String version of sdk.
*/ */
public static String getSdkVersion() { public static String getSdkVersion() {
var version = sdkVersion.get();
if (sdkVersion != null) { if ((version != null) && !version.isBlank()) {
return sdkVersion; return version;
} }
try (InputStream input = Version.class.getResourceAsStream("/sdk_version.properties");) { try (InputStream input = Version.class.getResourceAsStream("/sdk_version.properties")) {
Properties properties = new Properties(); Properties properties = new Properties();
properties.load(input); properties.load(input);
sdkVersion = "dapr-sdk-java/v" + properties.getProperty("sdk_version", "unknown"); var v = properties.getProperty("sdk_version", null);
} catch (IOException e) { if (v == null) {
sdkVersion = "unknown"; throw new IllegalStateException("Did not find sdk_version property!");
} }
return sdkVersion; if (v.isBlank()) {
throw new IllegalStateException("Property sdk_version cannot be blank.");
}
version = "dapr-sdk-java/v" + v;
sdkVersion.set(version);
} catch (IOException e) {
throw new IllegalStateException("Could not load sdk_version property!", e);
}
return version;
} }
} }