Reputation: 9301
When project is built with Maven
it is possible to get implementation version like this.
Is it possible to do that or something with Gradle?
I moved from Maven to Gradle with my app.
With Maven build I was able to display application version like Application vX.X.X
where X.X.X
was retrieved from implementation version. It that possible with Gradle?
Basically I want that version was resolved automatically.
Upvotes: 2
Views: 8107
Reputation: 15504
jar {
manifest {
attributes('Main-Class': 'Your main class',
'Implementation-Title': 'Your title',
'Implementation-Version': 'You version')
}
}
or if you use shadowJar
shadowJar {
manifest {
attributes 'Main-Class': 'Your main class'
attributes 'Implementation-Title': 'Your title'
attributes 'Implementation-Version': 'You version'
}
}
Then in the java sources you could use:
getClass().getPackage().getImplementationVersion()
getClass().getPackage().getImplementationTitle()
See more info in the Gradle doc: https://docs.gradle.org/current/userguide/java_plugin.html#sub:manifest
Upvotes: 10