abstract class Greeting : DefaultTask() {
// Configurable by the user
@get:Input
abstract val greeting: Property<String>
// Read-only property calculated from the greeting
@Internal
val message: Provider<String> = greeting.map { it + " from Gradle" }
...
}
Is there a way to connect multiple Properties this way? Let’s say, for example, if we had another Property
Thanks Björn! I already followed what I understood of your advice But I don’t want to simply go away without completing my example. Besides, I have another related question…
So I went from Zip.java to AbstractArchiveTask.java, more specifically, this block:
I see it’s simply using a convention to bind things together.
What I needed is a bit more convoluted (yet affordable in configuration phase), but just to complement my example, my implementation uses this approach:
abstract class Greeting : DefaultTask() {
@get:Input
abstract val greeting: Property<String>
@get:Input
abstract val name: Property<String>
@get:Internal
abstract val message: Property<String>
init {
message.convention( project.provider {
return@provider "${greeting.get()}, ${name.get()}"
}
}
...
}
Worked like a charm(although message is no longer immutable, because it’s a Property. But that’s irrelevant for now…)
But I’m wondering: isn’t using getProject() in a custom Task a bad practice nowadays?
I assumed that because there is a growing emphasis on using Service Injection instead of things like getProject.exec(...).