is it possible for Gradle to execute a task before calling
gradle build
Something like precompile. Someone please help. Is something like this possible and how?
is it possible for Gradle to execute a task before calling
gradle build
Something like precompile. Someone please help. Is something like this possible and how?
On
The left shift operator << was removed in Gradle 5.
In my case I had an Android project using a Java sub project and this worked:
task myTask {
doLast {
println 'do it before build'
}
}
assemble.dependsOn myTask
Regarding the initial question this should be the syntax now:
task myTask {
doLast {
println 'do it before build'
}
}
build.dependsOn myTask
// or for Android
preBuild.dependsOn myTask
On
This is for Kotlin DSL (build.gradle.kts):
tasks.register/* OR .create */("MyTask") {
doLast {
println("I am the task MyTask")
}
}
tasks.build {
dependsOn("MyTask")
}
// OR another notation
// tasks.named("build") {
// dependsOn(tasks["MyTask"])
// }
For more information see Gradle documentation: Adding dependencies to a task.
You can do it in this way:
Thanks to that task
preBuildwill be automatically called beforebuildtask.If you want to run
preBuildin configuration phase (previous example runpreBuildinexecutionphase) you can do it in this way:More about gradle build lifecycle can be read here http://www.gradle.org/docs/current/userguide/build_lifecycle.html.