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-antrun-plugin.version>1.8</maven-antrun-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.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
@ -156,6 +157,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>

View File

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

View File

@ -16,10 +16,11 @@ package io.dapr.utils;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
public final class Version {
private static String sdkVersion = null;
private static volatile AtomicReference<String> sdkVersion = new AtomicReference<>();
/**
* Retrieves sdk version from resources.
@ -27,20 +28,31 @@ public final class Version {
* @return String version of sdk.
*/
public static String getSdkVersion() {
var version = sdkVersion.get();
if (sdkVersion != null) {
return sdkVersion;
if ((version != null) && !version.isBlank()) {
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.load(input);
sdkVersion = "dapr-sdk-java/v" + properties.getProperty("sdk_version", "unknown");
} catch (IOException e) {
sdkVersion = "unknown";
var v = properties.getProperty("sdk_version", null);
if (v == null) {
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;
}
}