By default, all gradle java projects have a version
property. Typically, this looks something like:
allprojects {
apply plugin: 'java'
// ...
// configure the group and version for this project
group = 'org.example'
version = '0.2-SNAPSHOT'
}
Is there a way to make the "version" property defined here available to the built java code? What I would like to have is a class like this in the project:
public class BuildVersion {
public static String getBuildVersion(){
return // ... what was configured in gradle when project was built
}
}
I imagine that this could be done through some kind of source code generation. Or by letting gradle write the variable to some sort of config file in src/main/resources
. Is there a "standard" (i.e. generally accepted) way to do this in Gradle?