Caleb Cushing
06/05/2024, 7:25 PMvar printVersion = tasks.register("printVersion") {
outputs.upToDateWhen { false }
println(version)
}
> Task :printVersion UP-TO-DATE
Skipping task ':printVersion' as it has no actions.Benjamin Hoogterp
06/05/2024, 7:29 PMCaleb Cushing
06/05/2024, 7:31 PMCaleb Cushing
06/05/2024, 7:31 PM:printVersion of type `org.gradle.api.DefaultTask`: cannot serialize Gradle script object references as these are not supported with the configuration cache.Caleb Cushing
06/05/2024, 7:33 PMVampire
06/05/2024, 7:36 PMversion is really project.version
Store project.version in a local variable, then CC is happy.
Besides that, you don't need the outputs.upToDateWhen, because you did not declare any outputs, your task will never be up-to-date anyway. And if you would need to do something like that, better use doNotTrackState() instead, but also that is not necessary here.Vampire
06/05/2024, 7:36 PMval printVersion by tasks.registering {
val version = version
doLast {
println(version)
}
}
should do what you want I thinkVampire
06/05/2024, 7:37 PMprintln goes to stdout which goes to lifecycle log level which would be suppressed when using -q 🙂Caleb Cushing
06/05/2024, 7:42 PMCaleb Cushing
06/05/2024, 7:42 PMCaleb Cushing
06/05/2024, 7:43 PMvar printVersion = tasks.register("printVersion") {
val version = project.providers.provider { this.project.extensions.getByType(SemverExtension::class).gitDescribed }
doLast { println(version.get()) }
}Vampire
06/05/2024, 7:47 PM❯ ./gradlew printVersion --quiet
0.11.1Huh, ok, must have remembered wrongly, either the log level on which stdout is captured or what quiet displays
this would be a lazy versionyes
meaning that the version won't get calculated until the dolast block is called right?no Well, depends on whether CC is enabled. Without CC, yes. With CC it would be evaluated at the time the CC entry is serialized. When CC is reused it will not be reevaluated but the value from CC is used. If that is not what you need, you need to use a value source instead.
Caleb Cushing
06/05/2024, 7:53 PMVampire
06/05/2024, 8:10 PMCaleb Cushing
06/05/2024, 8:38 PMCaleb Cushing
06/05/2024, 8:59 PM