Skip to content

Instantly share code, notes, and snippets.

@StefMa
Created August 30, 2018 14:33
Show Gist options
  • Save StefMa/f744654787df010bafd9646017358aa0 to your computer and use it in GitHub Desktop.
Save StefMa/f744654787df010bafd9646017358aa0 to your computer and use it in GitHub Desktop.
Gradle inferred task dependency
open class TestingTask : DefaultTask() {
@InputFiles
var inputDirs = mutableListOf<Task>()
@OutputDirectory
var out: File? = null
@TaskAction
fun createOutputDir() {
println("Executed task named ‘$name' \uD83C\uDF89")
}
}
tasks.register("first", TestingTask::class.java) {
inputDirs.add(task("emptyTask"))
out = File("$buildDir/firstOutput")
}
tasks.register("second", TestingTask::class.java) {
inputDirs.add(tasks.getByName("first"))
out = File("$buildDir/secondOutput")
}
$ ./gradlew second
> Task :first
Executed task named 'first' 🎉
> Task :second
Executed task named 'second' 🎉
BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 executed
$ ./gradlew second
BUILD SUCCESSFUL in 0s
2 actionable tasks: 2 up-to-date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment