I have a composite Gradle (7.x) build and want to edit the root project gradle file to permanently prevent a specific included task from executing. I can successfully accomplish this from the command line with -x :included-build:bad-task
but cannot figure out how to permanently accomplish the same thing within the root gradle script. None of the solutions from these questions seem to work:

- 128
- 1
- 10
1 Answers
If you know "how" it's included, you can remove it.
For example, check
depends on checkstyleTest
, and can be removed via check.dependsOn.remove("checkstyleTest")
See here: https://discuss.gradle.org/t/how-to-remove-a-task-dependency/7481
It might be a matter of some detective work to find where it's brought in. Things like ./gradlew whateverTask --dry-run
can be used to show the progression. Various temporary tasks could be used to output config information.
Edit 1
Understanding it is hard to know exactly your needs without more context. But, depending on your needs, the below might work from your top project:
gradle.projectsEvaluated {
childProjects["included-build"].tasks.build.dependsOn -= "bad-task"
}
The main points being...
- The task is removed after the project is evaluated (so it exists first).
- The remove uses the
-=
operator. PreventsRemoving a task dependency from a task instance is not supported.
which happens if you use.remove
- Using Gradle 8.0.1
Running this with something like successfully removes check
from build
.
childProjects["application"].tasks.build.dependsOn -= "check"

- 887
- 8
- 17
-
Sorry I'm not following here. I know precisely where in my root build the included build is referenced ... now what? The above link, at a quick glance, doesn't seem applicable to a composite build. – Paul Galbraith Feb 28 '23 at 21:47
-
Edited for sub-project using `gradle.projectsEvaluated`. – User51 Mar 01 '23 at 14:39
-
This would probably work for a task brought in via a subproject, but it doesn't find tasks from included builds of a composite build. https://docs.gradle.org/current/userguide/composite_builds.html – Paul Galbraith Mar 01 '23 at 15:54