Niels Doucet
03/04/2026, 11:23 AMproject.version during a task action?Martin
03/04/2026, 11:24 AMNiels Doucet
03/04/2026, 11:30 AMephemient
03/04/2026, 1:52 PMabstract class MyTask : DefaultTask() {
@get:Input
val version: String = project.version.toString()
}
tasks.register<MyTask>("myTask")
or
abstract class MyTask : DefaultTask() {
@get:Input
abstract var version: Property<String>
}
tasks.register<MyTask>("myTask") {
version.set(project.version.toString())
}
then it'll be captured when the task is first configured, and if you do something like
abstract class MyTask : DefaultTask() {
@get:Input
abstract val version: Property<String>
}
tasks.register<MyTask>("myTask") {
version.set(project.provider { project.version.toString() })
}
then it'll be captured at the end of configurationTrevJonez
03/04/2026, 4:33 PMProperty<String> that is set from project.providers.gradleProperty("version")?
I guess that assumes you have a single version for a whole build...TrevJonez
03/04/2026, 4:34 PMVampire
03/04/2026, 4:41 PMproject.providers.gradleProperty("version") would only work if the version is actually coming from a Gradle property like when you have it in gradle.properties, but even then the version could be changed in the build script or by a plugin.
Safest currently should be the last variant in the comment before yours, having a Provider<String> in the task like you should always have and setting value or convention to a provider that reads it from project. Without configuration cache it will then be read when the inputs for the task are fingerprinted, with configuration cache at the time the configuration cache entry is calculated.
Hopefully with Gradle 10 and the great propertyization it will maybe be a Provider<String> in Project already.Javi
03/05/2026, 5:53 PMI suppose it's not a lazy propertyTechnically it is any object, so it can be lazy, a lot of semver plugins do that, so you should avoid calling it eagerly.
Niels Doucet
03/06/2026, 2:41 PMNiels Doucet
03/06/2026, 2:42 PM