How to change the "version" property depending on the project build status "up-to-date"?


(leif hanack) #1

I’m thinking of changing the manifest of a jar or the jar name itselfs every time some changes are detected. I.e. so long a “gradle build” prints “up-to-date” I want to keep the jar name unchanged. In all other cases I want to create a new version.

Hopefully it is clear what I’m looking for.

I tried s.th. like

subprojects {

version = new Date().format(“yyyyMMdd-mm-tt-ss”)

… }

but then, every time a new jar is built, which is clear to me after rethinking it. But how could a solution to my problem look like?

Hope you can help.

Thanks, Leif


(detelinyordanov) #2

About changing the manifest without re-generating the jar - there was already a similar question - how one could exclude certain manifest headers from the up-to-date check, see Input files upTodate-check customization. About jar filename - I think that if you change the version, the jar task will always re-execute as it checks whether the output jar file is available or not. You could probably change the filename after the jar task executes, but then you will have to also adjust the name of the artifact that it adds to the ArtifactHandler, otherwise you will not be able to upload this artifact and other projects will not be able to resolve it.


(Luke Daley) #3

In the Gradle build, we use the modification date of the most recently modified source file. This is a reasonable approximation, and avoids this problem.

https://github.com/gradle/gradle/blob/master/gradle/versioning.gradle#L13


(leif hanack) #4

thank you for the pointer, this is what i was looking for.