Slackbot
01/18/2023, 7:26 PMTyler Helmuth
01/18/2023, 7:34 PMinterface ExtJSPluginExtension {
Property<String> getAppDir()
}
def extension = project.extensions.create("extjs", ExtJSPluginExtension)
Jendrik Johannes
01/18/2023, 7:36 PMProperty<..>
s and register it as an extension.
I have a quite minimal example here:
https://github.com/jjohannes/understanding-gradle/blob/main/07_Implementing_Tasks_[…]gic/java-plugins/src/main/kotlin/my-java-application.gradle.kts
https://github.com/jjohannes/understanding-gradle/blob/main/07_Implementing_Tasks_[…]/java-plugins/src/main/kotlin/myproject/tasks/MyAppExtension.kt
https://github.com/jjohannes/understanding-gradle/blob/main/07_Implementing_Tasks_and_Extensions/my-project/app/build.gradle.kts#L5-L7Tyler Helmuth
01/18/2023, 7:37 PMJaron Couvreur
01/19/2023, 11:55 AMCannot query the value of extension 'fooExtension' property 'foo' because it has no value available.
Jaron Couvreur
01/19/2023, 11:57 AMinterface FooExtension {
val foo: Property<String>
}
val fooExtension = extensions.create<FooExtension>("fooExtension")
tasks {
// doesn't work
println(fooExtension.foo.get())
// works
withType<Test>().configureEach {
println(fooExtension.foo.get())
}
}
Tyler Helmuth
01/19/2023, 5:08 PMJendrik Johannes
01/20/2023, 11:41 AMget()
at all. Instead, you just pass the provider in the task configuration. Then get()
is only called during task execution. That's the idea behind the provider/property concept - you only pass around references to values. This way, the order in which things are done during configuration no longer matters.
Some Tasks in Gradle and plugins unfortunately do not support providers yet. 😕 Then what you describe is usually sufficient - use task configuration avoidance (named()
/ forEach()
) so that get()
is called late in the configuration phase.
Still, I would be interested why you had to call get()
for the Jar task. The API of the task is not perfect, but usually there is some way to use it without calling get()
already. Mind to share an example?