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?
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.
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.
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.
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.
You can try e.g.:
unwantedTask.enabled = false
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 } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With