Git.SemVersioning.Gradle icon indicating copy to clipboard operation
Git.SemVersioning.Gradle copied to clipboard

Running Two Gradle Tasks Simultaneously on the Same Command Line

Open haikalrios opened this issue 11 months ago • 1 comments

I am attempting to run two Gradle tasks on the same command line, using the following command:

./gradlew releaseVersion build

However, when executing the releaseVersion and build tasks together, I noticed that the build version does not reflect the version of the tag/commit generated by the releaseVersion task. I suspect this might be related to Gradle's lifecycle, where configuration tasks are executed only once. It seems the plugin calculates the version and assigns it to a lazy property.

I executed Gradle without parallel mode enabled and also tried applying the mustRunAfter configuration on the build task, specifying that it should run after releaseVersion.

Is this behavior expected? Shouldn't there be an update to the version property after the releaseVersion task execution?

I managed to synchronize the build version with what would be generated after the version tag/commit by including the parameter -PdefaultPreRelease=

haikalrios avatar Mar 04 '24 23:03 haikalrios

Hi, I never thought about this use case. The version is stored in lazy properties so it can be accessed more than once without the need to calculate it again.

Have you tried setting your project version from a task instead of directly in the build script? That way the release task should be able to perform its job before the version is calculated I think.

var initVersion = tasks.register("initVersion") {
    doLast {
        version = semver.version
    }
}

tasks.named<Task>("classes") {
    dependsOn(initVersion)
}

jmongard avatar Mar 05 '24 22:03 jmongard