Skip to content

Commit 561b210

Browse files
committed
HBX-2962: Inject the version string during the build
Signed-off-by: Koen Aers <[email protected]>
1 parent b228bab commit 561b210

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,23 @@
178178
</testResource>
179179
</testResources>
180180
<plugins>
181+
<plugin>
182+
<groupId>org.jboss.maven.plugins</groupId>
183+
<artifactId>maven-injection-plugin</artifactId>
184+
<configuration>
185+
<bytecodeInjections>
186+
<bytecodeInjection>
187+
<expression>${project.version}</expression>
188+
<targetMembers>
189+
<methodBodyReturn>
190+
<className>org.hibernate.tool.Version</className>
191+
<methodName>versionString</methodName>
192+
</methodBodyReturn>
193+
</targetMembers>
194+
</bytecodeInjection>
195+
</bytecodeInjections>
196+
</configuration>
197+
</plugin>
181198
<plugin>
182199
<groupId>org.apache.maven.plugins</groupId>
183200
<artifactId>maven-surefire-plugin</artifactId>

src/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.2.14-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)