I would like to obtain a Gradle project version in my Java code.
In Maven, it can be done this way:
version.properties:
version=${project.version}
which resolves to:
version=1.0-SNAPSHOT
in jar/war if we add this to pom.xml:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Is there any convenient way to achieve similar result in Gradle? Or should I manually write a task that produces a property file with the project version and then read it in my code?
src/main/resources/version.properties:
version=${projectVersion}
build.gradle:
apply plugin: "java"
processResources {
expand projectVersion: project.version
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With