Gradle: Make build version available to Java
<p>By default, all gradle java projects have a <code>version</code> property. Typically, this looks something like:</p>

<pre><code>allprojects {
    apply plugin: 'java'
    // ...

    // configure the group and version for this project
    group = 'org.example'
    version = '0.2-SNAPSHOT'
}
</code></pre>

<p>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:</p>

<pre><code>public class BuildVersion {

    public static String getBuildVersion(){
        return // ... what was configured in gradle when project was built
    }

}
</code></pre>

<p>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 <code>src/main/resources</code>. Is there a "standard" (i.e. generally accepted) way to do this in Gradle?</p>