diff --git a/pom.xml b/pom.xml index 295dfb23ec..86643ed823 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ 3.1.1 1.8 2.7 + 3.3.1 3.13.0 11 11 @@ -156,6 +157,11 @@ + + org.apache.maven.plugins + maven-resources-plugin + ${maven-resources-plugin.version} + diff --git a/sdk/pom.xml b/sdk/pom.xml index df82510ae5..5e52cf871b 100644 --- a/sdk/pom.xml +++ b/sdk/pom.xml @@ -21,6 +21,7 @@ --add-opens java.base/java.util=ALL-UNNAMED + @@ -28,12 +29,6 @@ org.slf4j slf4j-api - - org.apache.maven.plugins - maven-resources-plugin - 3.3.1 - maven-plugin - io.dapr dapr-sdk-autogen @@ -169,6 +164,10 @@ + + org.apache.maven.plugins + maven-resources-plugin + org.apache.maven.plugins maven-source-plugin diff --git a/sdk/src/main/java/io/dapr/utils/Version.java b/sdk/src/main/java/io/dapr/utils/Version.java index e55e77f4a2..7b0ef2f49f 100644 --- a/sdk/src/main/java/io/dapr/utils/Version.java +++ b/sdk/src/main/java/io/dapr/utils/Version.java @@ -16,10 +16,11 @@ 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 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"); + var v = properties.getProperty("sdk_version", null); + if (v == null) { + throw new IllegalStateException("Did not find sdk_version property!"); + } + + if (v.isBlank()) { + throw new IllegalStateException("Property sdk_version cannot be blank."); + } + + version = "dapr-sdk-java/v" + v; + sdkVersion.set(version); } catch (IOException e) { - sdkVersion = "unknown"; + throw new IllegalStateException("Could not load sdk_version property!", e); } - return sdkVersion; + return version; } }