Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable a task in build.gradle

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?

like image 413
NO127 Avatar asked Nov 09 '17 02:11

NO127


People also ask

How do I enable tasks in Gradle?

Configure running triggers for Gradle tasks IntelliJ IDEA lets you run Gradle tasks before your project's execution or set other conditions using the task activation configuration. In the Gradle tool window, right-click a Gradle project. From the context menu, select Tasks Activation.

Does Gradle build run all tasks?

You can execute multiple tasks from a single build file. Gradle can handle the build file using gradle command. This command will compile each task in such an order that they are listed and execute each task along with the dependencies using different options.

How do I stop build Gradle?

Note that it requires you to have gradlew executable in the project directory (it's there by default when using Android Studio). After the installation you can find "Gradle Stop" button on Main Toolbar and inside Run Menu.

What does Gradle clean task do?

clean will delete a build directory, all your classes will be removed for a fresh compile. assemble will create an archive (JAR) file from your Java project and will run all other tasks that require compile, test and so on.


2 Answers

You can try e.g.:

unwantedTask.enabled = false 
like image 97
Opal Avatar answered Oct 03 '22 14:10

Opal


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     } } 
like image 32
NO127 Avatar answered Oct 03 '22 16:10

NO127