Task Utilities
Configure a task upon optional configuration
Sometimes a task might never registered, but if it does get registered and later created, adding configuration at that point, is a good option. For this you can use TaskTools.whenNamed
Lazy evaluate objects to task instances
The Task.dependsOn
method allows various ways for objects to be evaluated to tasks at a later point in time.
Unfortunately this kind of functionality is not available via a public API and plugin authors would want to create links between tasks for domain reasons, have to find other ways of creating lazy-evaluated task dependencies.
In 0.17.0 we added TaskUtils.taskize
to help relieve this problem, but from 1.3 the better solution is to use TaskTools.taskize
.
-
Gradle task.
-
Gradle TaskProvider.
-
Any CharSequence including String and GString.
-
Any Gradle Provider to the above types
-
Any Callable implementation including Groovy Closures that return one of the above values.
-
Any iterable sequence of the above types
-
A Map for which the values are evaluated. (The keys are ignored).
SkipWhenEmpty and IgnoreEmptyDirectories
In Gradle 6.8 @IgnoreEmptyDirectories
was added.
In Gradle 7.x there is a deprecation warning for using @SkipWhenEmpty
with FileTree
.
In order to keep forward-compatibility, but compile with a version prior to Gradle 6.8, a small idiom can be folowed.
Consider that you had something like this.
@SkipWhenEmpty
@InputFiles
FileTree getSourceFiles() {
this.mySourceFiles (1)
}
1 | Assuming that the FileTree is held in a field called mySourceFiles . |
Change the above tobe
@Internal
FileTree getSourceFiles() {
this.mySourceFiles
}
Then change the constructor to include
MyTask() {
projectOperations.tasks.ignoreEmptyDirectories(inputs,this.mySourceFiles)
}
It is also possible to configure using additional options and path sensitivity.
// Assume these import
import org.gradle.api.tasks.PathSensitivity
import static org.ysb33r.grolifant.api.core.TaskInputFileOptions.*
MyTask() {
projectOperations.tasks.inputFiles(
inputs,
this.mySourceFiles,
PathSensitivity.RELATIVE,
OPTIONAL, SKIP_WHEN_EMPTY, IGNORE_EMPTY_DIRECTORIES, NORMALIZE_LINE_ENDINGS
)
}