Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run my task before a plugin's task?

Tags:

gradle

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?

like image 766
Corey Ogburn Avatar asked Dec 15 '22 13:12

Corey Ogburn


1 Answers

You can declare task dependencies explicitly.

Add following code to your build.gradle file

tasks.war.dependsOn("yourTaskNameHere")
tasks["yourTaskNameHere"].dependsOn("clean")
like image 169
Nikita Skvortsov Avatar answered Jun 07 '23 04:06

Nikita Skvortsov