Corey Ogburn
Corey Ogburn

Reputation: 24717

Run my task before a plugin's task?

We're using a gradle file to build a Java WAR file. I know very little about gradle. At the top of build.gradle:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'war'

We run the gradle with gradle clean install. I'm not sure where these tasks are defined but I assume they're in one of the plugins (I'd guess war).

When I run gradle clean install it seems to print the tasks that it are run:

:clean
:compileJava
:processResources
:classes
:war
:install

Correct me if I'm wrong, but it seems that the task install dependsOn compileJava, processResources, classes, and war.

I need a task I've written to run sometime after clean but sometime before war. Preferably without modifying the plugin.

I've tried indicating that my task mustRunAfter processResources but it doesn't work that way.

How can I inject my task as a dependency on install before the dependency war?

Upvotes: 5

Views: 8653

Answers (1)

Nikita Skvortsov
Nikita Skvortsov

Reputation: 4923

You can declare task dependencies explicitly.

Add following code to your build.gradle file

tasks.war.dependsOn("yourTaskNameHere")
tasks["yourTaskNameHere"].dependsOn("clean")

Upvotes: 12

Related Questions