问题
I want to skip some tasks when I run gradle build. I know that it can be done from command line with -x
:
gradle build -x unwantedTask
My question is how can the same result be achieved in the build.gradle?
回答1:
You can try e.g.:
unwantedTask.enabled = false
回答2:
Because I need to disable a bunch of tasks, so I use the following codes before apply plugin:
in my build.gradle
file:
tasks.whenTaskAdded {task ->
if(task.name.contains("unwantedTask")) {
task.enabled = false
}
}
回答3:
As hinted to by @LukasKörfer in a comment, to really remove a task from the build, instead of just skipping it, one solution is to add this to your build script:
project.gradle.startParameter.excludedTaskNames.add('yourTaskName')
However this seems to remove the task for all subprojects.
来源:https://stackoverflow.com/questions/47192746/how-can-i-disable-a-task-in-build-gradle