Gradle version of the project outside the assembly. Gradle at runtime

I want to get the version of a Gradle project in my Java code.

In Maven, this can be done like this:

version.properties:

version=${project.version}    

      

which permits:

version=1.0-SNAPSHOT    

      

to jar / war if we add this to pom.xml:

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>

      

Is there a convenient way to achieve a similar result in Gradle? Or do I have to manually write a task that creates a properties file with a project version and then read it into my code?

+3


source to share


1 answer


Src / main / resources / version.properties:

 version=${projectVersion}

      



build.gradle:

apply plugin: "java"

processResources {
    expand projectVersion: project.version
} 

      

+6


source







All Articles