21 lines
1.1 KiB
Markdown
21 lines
1.1 KiB
Markdown
### Sample on how to generate a comprehensive version info including Git-commit-ids and build-times.
|
||
|
||
Versioninfo is generated in the output-jar and also as Java-class for comsumption e.g.
|
||
in user-output.
|
||
|
||
- Ensure your project is in a Git-repositiory (with at least one commit)
|
||
- Put `BuildVersion.java` in a new folder `templates` under the `src/main´-directory and modify
|
||
as needed.
|
||
- Add `<resources>` and `<plugins>` from this pom.xml to your pom.xml
|
||
- Add `<myapp.version>1.0</myapp.version>` to the `<properties>` section. This will be used
|
||
as main "end-user" version .
|
||
- Run `mvn resources:resources` to generate the final buildversion
|
||
- Now you can add something like `System.out.println(BuildVersion.BUILD);` to your code
|
||
to show the version to the user.
|
||
|
||
With this also a git.properties file will be included in the output-JAR.
|
||
|
||
Note: In `BuildVersion.java` don't put `@`chars before a template-field, otherwise it won't be processed correctly!
|
||
|
||
See [git-commit-id-plugin](https://github.com/git-commit-id/git-commit-id-maven-plugin/blob/master/maven/docs/using-the-plugin.md) for more
|