Reputation: 8116
I am working with a third-party that runs gradle as part of a bigger process which leaves me with limited options on how to interact with gradle.
I want to skip some task but I don't have the ability to pass extra parameters to gradle. e.g. --exclude-task annoyingTask
I can pass JVM args, set environment variables and use the init.gradle
in the home directory.
Can I use any of these to force the build to skip a task?
Upvotes: 1
Views: 489
Reputation: 22952
Since you don't have access to the Gradle build script itself judging by the restrictions you have, Initialization Scripts is the only option you have.
If you know the name of the tasks, you can do something like the following (pseudo):
init.gradle
gradle.taskGraph.whenReady {
def annoyingTask = allTasks.filter { name == "someAnnoyingTask" }
annoyingTask.configure {
onlyIf {
System.getenv("skip") == true
}
}
}
Refs:
https://docs.gradle.org/current/userguide/init_scripts.html
https://docs.gradle.org/current/javadoc/org/gradle/api/execution/TaskExecutionGraph.html
https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:using_a_predicate
Upvotes: 2