Eric VANTILLARD
04/07/2025, 8:40 AMincludeEmptyDirs property using a custom project extension.
The extension will have a Property<Boolean>.
How to apply my extension property lazily ?
As a workaround I was thinking to use doFirst{} during my task configuration :
doFirst {
includeEmptyDirs = extension.includeEmptyDirs.get()
}Thomas Broyer
04/07/2025, 8:50 AMafterEvaluate {} (and do finalizeValue() there to make sure the extension cannot be reconfigured afterwards)
doFirst {} should also work I think; but make sure you also declare your extension property as task input (inputs.property("my-plugin-includeEmptyDirs", extension.includeEmptyDirs)) for proper up-to-date checksThomas Broyer
04/07/2025, 8:53 AMFileSystemOperations, that way you can easily configure the CopySpec at execution time.Vampire
04/07/2025, 7:44 PMCopy task, but a copy { ... } call at execution time is the better way, in similar situations I would recommend not to use a Property in the extension, but a function the body of which does the configuration change.Eric VANTILLARD
04/10/2025, 10:01 AMProperty<T> are not Observable?
If it was the case I could use it to configure non lazy taks.
I would end up using it like this :
open class JavaOptionsExtension @Inject constructor(objectFactory: ObjectFactory) {
val javaVersion: ObservableProperty<JavaVersion> = objectFactory.observableProperty()
}
the<JavaOptionsExtension>().apply {
javaVersion.onChange {
java{
sourceCompatibility= javaVersion.get()
targetCompatibility= javaVersion.get()
}
}
}Vampire
04/10/2025, 10:06 AMVampire
04/10/2025, 10:07 AMVampire
04/10/2025, 10:08 AMEric VANTILLARD
04/10/2025, 10:44 AMVampire
04/10/2025, 10:51 AMVampire
04/10/2025, 10:52 AMvar observed = objects.property<String>()
var changed = objects.property<String>()
observed = changed
changed.set("foo")Vampire
04/10/2025, 10:54 AMvar observed = objects.property<String>()
var changed = objects.property<String>()
observed = changed
changed.set(tasks.foo.map { it.outputs.files.singleFile.readText() })Thomas Broyer
04/10/2025, 10:54 AMThomas Broyer
04/10/2025, 10:57 AMjava {
sourceCompatibility = the<JavaOptionsExtension>().javaVersion
targetCompatibility = the<JavaOptionsExtension>().javaVersion
}Thomas Broyer
04/10/2025, 11:02 AMEric VANTILLARD
04/10/2025, 11:27 AMVampire
04/10/2025, 11:56 AMGradle is moving to make everything a Property in v9 (even using bytecode rewriting at runtime IIUC) so this should not be needed in the long term.Unfortunately not 😞
Vampire
04/10/2025, 11:56 AMVampire
04/10/2025, 11:56 AM