I have a Groovy application that I build with Gradle. As usual I have defined the application version number/string in the build.gradle script.
Now I want to use that version string within the Groovy application, as hard-coded static piece of information. For example as a final static member in the main application class:
class MyApp {
final static APP_VERSION = "0.1"
}
Since the version information comes from the build.gradle script, that Groovy class member above needs to be set by Gradle before the sources are compiled.
In other words: I need a Gradle task that allows me to set the value of a variable in the Groovy sources, before they are built by Gradle. I could for search for that value via regular expression and replace it in the Groovy source file, but that feels a bit clunky.
Any "best practice" ideas how to achieve that?