Skip to content

Commit 83cde7c

Browse files
Use dynamic version inside app (#5)
* ci: inject version during runtime * ci: use programmatic approach to get version
1 parent 9de99bd commit 83cde7c

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@
103103
</properties>
104104

105105
<build>
106+
<resources>
107+
<resource>
108+
<directory>src/main/resources</directory>
109+
<filtering>true</filtering>
110+
</resource>
111+
</resources>
106112
<pluginManagement>
107113
<plugins>
108114
<plugin>

src/main/java/com/godiddy/cli/GodiddyRootCommand.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
name = "godiddy-cli",
1616
description = "Godiddy Universal DID Operations",
1717
footer = "See https://docs.godiddy.com/ for more information.",
18-
version = "1.0.0",
18+
versionProvider = GodiddyRootCommand.GodiddyVersionProvider.class,
1919
mixinStandardHelpOptions = true,
2020
subcommands = {
2121
ConfigRootCommand.class,
@@ -32,4 +32,17 @@
3232
}
3333
)
3434
public class GodiddyRootCommand extends GodiddyAbstractCommand implements Callable<Integer> {
35-
}
35+
36+
static class GodiddyVersionProvider implements CommandLine.IVersionProvider {
37+
@Override
38+
public String[] getVersion() {
39+
return new String[] { Version.VERSION };
40+
}
41+
}
42+
43+
@Override
44+
public Integer call() {
45+
// Your existing implementation
46+
return 0;
47+
}
48+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.godiddy.cli;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.util.Properties;
6+
7+
public final class Version {
8+
9+
private static final String VERSION_FILE = "version.properties";
10+
public static final String VERSION;
11+
12+
static {
13+
String version;
14+
try (InputStream is = Version.class.getClassLoader().getResourceAsStream(VERSION_FILE)) {
15+
if (is == null) {
16+
throw new RuntimeException("Version properties file not found: " + VERSION_FILE);
17+
}
18+
19+
Properties props = new Properties();
20+
props.load(is);
21+
22+
version = props.getProperty("version");
23+
if (version == null || version.isEmpty()) {
24+
throw new RuntimeException("Version not defined in properties file");
25+
}
26+
} catch (IOException e) {
27+
throw new RuntimeException("Failed to load version properties", e);
28+
}
29+
30+
VERSION = version;
31+
}
32+
33+
private Version() {
34+
// Prevent instantiation
35+
}
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=${project.version}

0 commit comments

Comments
 (0)