jmongard / Git.SemVersioning.Gradle

Gradle plugin for automatically versioning a project using semantic versioning and conventional commits with change log support based on git commit messages.
https://plugins.gradle.org/plugin/com.github.jmongard.git-semver-plugin
Apache License 2.0
38 stars 4 forks source link

Running Two Gradle Tasks Simultaneously on the Same Command Line #56

Open haikalrios opened 7 months ago

haikalrios commented 7 months ago

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=

jmongard commented 7 months ago

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)
}