Skip to content

Commit 13aed53

Browse files
committed
HBX-2962: Inject the version string during the build
Signed-off-by: Koen Aers <[email protected]>
1 parent 099e7db commit 13aed53

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

main/pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,26 @@
8686
</dependency>
8787
</dependencies>
8888

89+
<build>
90+
<plugins>
91+
<plugin>
92+
<groupId>org.jboss.maven.plugins</groupId>
93+
<artifactId>maven-injection-plugin</artifactId>
94+
<configuration>
95+
<bytecodeInjections>
96+
<bytecodeInjection>
97+
<expression>${project.version}</expression>
98+
<targetMembers>
99+
<methodBodyReturn>
100+
<className>org.hibernate.tool.Version</className>
101+
<methodName>versionString</methodName>
102+
</methodBodyReturn>
103+
</targetMembers>
104+
</bytecodeInjection>
105+
</bytecodeInjections>
106+
</configuration>
107+
</plugin>
108+
</plugins>
109+
</build>
110+
89111
</project>

main/src/main/java/org/hibernate/tool/Version.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
final public class Version {
66

7-
public static final String VERSION = "5.3.37-SNAPSHOT";
8-
97
private static final Version instance = new Version();
108

9+
public static final String VERSION = instance.versionString();
10+
1111
private static Logger log = Logger.getLogger( Version.class.getName() );
1212

1313
static {
@@ -22,6 +22,11 @@ public String getVersion() {
2222
return VERSION;
2323
}
2424

25+
public String versionString() {
26+
// This implementation is replaced during the build with another one that returns the correct value.
27+
return "UNKNOWN";
28+
}
29+
2530
public static Version getDefault() {
2631
return instance;
2732
}

0 commit comments

Comments
 (0)