researchgate / gradle-release

gradle-release is a plugin for providing a Maven-like release process for projects using Gradle
MIT License
859 stars 223 forks source link

Keeping a reference to the last released version #347

Open jmini opened 3 years ago

jmini commented 3 years ago

In my gradle.properties I want to keep trace of the version (example 1.6.0-SNAPSHOT) and the last released version lastVersion (example 1.5.3).

This allows me to use the lastVersion in different places (docs, baseline definition).


I am wondering if the release plugin could help me. Ideally:

The first commit: [PATCH] [Gradle Release Plugin] - pre tag commit: '1.6.0'.

Would update both values:

--- a/gradle.properties
+++ b/gradle.properties
@@ -1,4 +1,4 @@
-version=1.6.0-SNAPSHOT
-lastVersion=1.5.3
+version=1.6.0
+lastVersion=1.6.0

The second commit: [Gradle Release Plugin] - new version commit: '1.6.1-SNAPSHOT'.

--- a/gradle.properties
+++ b/gradle.properties
@@ -1,4 +1,4 @@
-version=1.6.0
+version=1.6.1-SNAPSHOT
 lastVersion=1.6.0

The idea I had until now was to add a new task that ensure that version == lastVersion during a release:

release {
    buildTasks = ['doRelease']
}

task doRelease {
    dependsOn(
        'checkLastVersionValue',
        // other release tasks
    )
}

task checkLastVersionValue {
    doLast {
        if(version.endsWith('SNAPSHOT')) {
            throw new GradleException("version '$version' ends with SNAPSHOT, this is not a release build!")
        }
        if(lastVersion != version) {
            throw new GradleException("lastVersion '$lastVersion' does not match version '$version', fix it in the 'gradle.properties' file.")
        }
    }
}

This is not perfect, but I least I will not forget to fix the value prior to a release.