Created
April 15, 2019 17:05
-
-
Save rdp/789e5c4cb6fda1841e86e722a2d152d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to get the build version by having maven create a file with the "build.timestamp" etc. in it: | |
You can set it yourself by filtering a "resource" properties file that declares it, then read it as a resource, a la: | |
String retrieveVersionFromResource() throws IOException { | |
try (InputStream br = getClass().getResourceAsStream("/auto-version.txt")) { // maven pom.xml specifies to setup auto-version.txt with some values for us | |
Properties props = new Properties(); | |
props.load(br); | |
return "build_version=" + props.get("project_version") + " " + props.get("build_date"); | |
} | |
} | |
where a file src/main/resources/auto-filtered of name "auto-version.txt" or "auto-version.props" or whatever you want to call it, exists | |
https://stackoverflow.com/a/52939311/32453 | |
in the pom build section: | |
<resources> | |
<resource> | |
<directory>src/main/resources-filtered | |
</directory> <!-- to get "current version" into resource properties file --> | |
<filtering>true</filtering> | |
</resource> | |
<resource> | |
<directory>src/main/resources</directory> <!-- apparently have to call it out now? lame --> | |
</resource> | |
</resources> | |
contents (spring boot style project) would be: | |
build_date=@maven.build.timestamp@ | |
project_version=@project.version@ | |
contents (non springboot style): | |
build_date=${maven.build.timestamp} | |
project_version=${project.version} | |
ref: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment