This message was deleted.
# configuration-cache
s
This message was deleted.
1
t
Can't you use
this.getProject().getGradle().getTaskGraph()
from your
@TaskAction
?
t
t
til (I must say my plugins are simple enough to never have stumbled on those restrictions)
t
huh, I tried again, and it works now... (I probably picked a too complex test to experiment on)
Copy code
@get:Internal // does not affect outputs
internal abstract val hasTask: Property<Boolean>
init {
    hasTask.convention(project.provider { project.gradle.taskGraph.hasTask(":myTask") })
}
@TaskAction fun f() { val hasTask = hasTask.get() ... }
j
I think using
project
inside task is discouraged
Why you don't provide it from outside?
t
I kept it inside, because it's totally internal, like a private function. Not an input.
j
you can provide it in the constructor as implementation detail too
t
(It doesn't matter where you wire it though, the problem would be the same even if it was captured in a lambda's anonymous inner class)
the project you mean?
j
you can do
Copy code
project.register<MyTask>("myTask", provider<Boolean> { project.hasTaskWhatever() })
Copy code
open class MyTask @Inject constructor(private val hasTaskWhatever: Provider<Boolean>) : DefaultTask()
I am not sure if it is possible to use
@Internal
plus
internal val hasTaskWhatever: ...
too
t
yeah, but when I mean implementation detail, I mean really internal to the task, if I expose it in the public constructor it puts the burden of creation to all users of the task, ending up with duplicate code. For input/output wiring, yes I agree that
project.register<T>("name") { prop.convention/set(...) }
is the best option, because those things change between usages.