This message was deleted.
# community-support
s
This message was deleted.
t
Was able to accomplish this using the following code in the script plugin
Copy code
interface ExtJSPluginExtension {
    Property<String> getAppDir()
}

def extension = project.extensions.create("extjs", ExtJSPluginExtension)
j
party gradlephant 1
t
Thanks 🙂 I'll check those examples
j
Hi. Am I correct in stating that you can only use extension values inside blocks of lazy configuration? Otherwise the extension hasn't received its value yet, and you get this error:
Copy code
Cannot query the value of extension 'fooExtension' property 'foo' because it has no value available.
for example like so:
Copy code
interface 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())
    }
}
t
@Jaron Couvreur I just ran into this myself. I had to use project.afterEvaluate to get the extension values to configure my "jar" task, but it seems dirty. edit: Found out that because I am configuring the jar task with a closure, it creates and configures the task eagerly. By removing the closure and using tasks.named("jar") { I am able to pick up the extension values.
j
Ideally, you won't have to call
get()
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?
👍 1