Task dependsOn, not updating file through git

I’m trying to use the researchgate gradle-release plugin. I have my versions of certain libraries set in gradle.properties, like so

version=0.14.0
commonVersion=0.15.0-SNAPSHOT
enterpriseVersion=0.16.0-SNAPSHOT

I need to remove the snapshot, so I’ve written a task

tasks {
    register("snapshotIncrementer") {
        group = "release"
        inputs.file("gradle.properties")
        outputs.file("gradle.properties")
        doFirst {
            val file = File("$projectDir/gradle.properties")
            val newLines = file.readLines().map { it.replace("-SNAPSHOT", "") }
            file.writeText(newLines.joinToString(separator = "\n"))

            exec {
                setIgnoreExitValue(true)
                commandLine("git", "commit", "-m", "Removing SNAPSHOT versions", "--", "gradle.properties")
            }
        }
        doLast {
            Thread.sleep(20000)
        }
    }
    "checkSnapshotDependencies" {
        dependsOn("snapshotIncrementer")
    }
}

That runs before the gradle-release plugin checks if snapshot versions are present. This succeeds in committing the gradle.properties file with the -SNAPSHOT removed, but no matter how long I Thread.sleep for, when the checkSnapshotDependencies task runs, it still sees the old version of the file. I am not sure why this would be unless gradle is doing some sort of optimizing and starting the second task thread before the snapshotIncrementer is done. Any ideas what I can do to get this working?


address-validation on  gradle [⇡] via 💎 v2.5.3 on 🐳 v18.06.1
➜ ./gradlew checkSnapshotDependencies -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=0.13.0 -Prelease.newVersion=0.14.0-SNAPSHOT                 
<-------------> 0% EXECUT
> Task :snapshotIncrementer:snapshotIncrementer
[gradle c2373c0] Removing SNAPSHOT versions
 1 file changed, 2 insertions(+), 2 deletions(-)

> Task :checkSnapshotDependencies FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':checkSnapshotDependencies'.
> Snapshot dependencies detected:
        address-validation: [com.promontech.enterprise:pt-enterprise-dependencies:0.16.0-SNAPSHOT, com.promontech.loanplatform:pt-lp-common:0.15.0-SNAPSHOT]

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 21s
2 actionable tasks: 2 executed

This waits 20 seconds and then continues, yet the gradle.properties file is still seen with the SNAPSHOT versions in it.

Looks like gradle was setting the version before I could modify it with my task. My solution is to run the two tasks separately with no dependency between the two. Kind of sucks, but it doesn’t seem possible to have a dependency that updates gradle.properties

checkSnapshotDependencies looks at the configured dependencies and has no reference to the properties file.

Where are the commonVersion and enterpriseVersion properties being used? Are you using those values to configure dependencies, or is some plugin doing that for you?

I’m using those to configure dependencies.

val commonVersion: String by project
val enterpriseVersion: String by project

ext {
    set("enterpriseVersion", enterpriseVersion)
    set("commonVersion", commonVersion)
    set("springBootVersion", "1.5.6.RELEASE")
    set("annotationProcessorVersion", "1.4.0")
    set("lpCalculatorVersion", "0.4.0")
    set("codehaus.woodstox.version", "4.4.1")
    set("googlemaps.service.version", "0.1.14")
    set("powermock.version", "1.7.1")
    set("mockito.version", "1.10.19")
    set("restassured.version", "2.9.0")
}```

I want my task to remove the snapshot before a plugin runs though.