Why is this an issue?
Using the Kotlin Gradle DSL, a task can be defined in several ways:
-
tasks.create(…)
will eagerly configure the task, regardless of whether it is required.
-
tasks.register(…)
lazily configures the task only when it is required. This happens when it is located using query methods such
as TaskCollection.getByName(java.lang.String)
, when it is added to the task graph for execution, or when Provider.get()
is
called on the return value of this method.
It is generally more efficient to use tasks.register(…)
instead of tasks.create(…)
as the task will not be configured
if it is not needed.
How to fix it
Replace tasks.create(…)
with tasks.register(…)
.
Code examples
Noncompliant code example
tasks.create("myTask") {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "My task."
// other configuration logic
doLast {
// ...
}
}
Compliant solution
tasks.register("myTask") {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "My task."
// other configuration logic
doLast {
// ...
}
}
Resources
Documentation
Standards