Build order for 'gradle clean build'

We have difficulty understanding why Gradle orders the builds as it does in a multi-project build.

Our two projects in this build are :web-grails and :web-js-html, where :web-grails has a compile dependency on :web-js-html. The build configs are as follows:

// web-grails/build.gradle

apply plugin: “grails”

repositories {

mavenLocal()

maven { url artifactory_url }

}

buildscript {

repositories {

mavenLocal()

maven { url artifactory_url }

}

dependencies {

classpath ‘org.grails:grails-gradle-plugin:2.0.1’

}

}

grails {

grailsVersion = ‘2.3.8’

groovyVersion = ‘2.3.0’

}

dependencies {

bootstrap ‘org.grails.plugins:tomcat:7.0.50’

compile “com.h2database:h2:1.3.173”

compile “org.grails.plugins:resources:1.2.7”

compile “org.grails.plugins:hibernate:3.6.10.13”

compile project(‘:web-js-html’)

}

The web-js-html/build.gradle config is as follows:

// web-js-html/build.gradle

apply plugin: ‘java’

ext {

webjarconfig = [

staticHTMLFilesDir : “${projectDir}/src/main/webfrontend”,

baseDir: “META-INF/resources/”,

subDir : “webjars/” + deployed_app_name

]

}

jar {

from(fileTree(webjarconfig.staticHTMLFilesDir)) {

into webjarconfig.baseDir + webjarconfig.subDir

}

outputs.file archivePath

}

If I invoke ‘gradle clean build’, then the following output will be displayed:

C:\projects\workspace\gradle-multiproject-template\demo-gradle-multiproject>gradle clean build -x test

Picked up _JAVA_OPTIONS: -Duser.home=“C:\dev\user_home”

:clean UP-TO-DATE

:web-js-html:compileJava UP-TO-DATE

:web-js-html:processResources UP-TO-DATE

:web-js-html:classes UP-TO-DATE

:web-js-html:jar

:web-grails:grails-clean

|Loading Grails 2.3.8

|Configuring classpath

|Running pre-compiled script

.

|Environment set to development

|Application cleaned.

Picked up _JAVA_OPTIONS: -Duser.home=“C:\dev\user_home”

:web-grails:clean

:web-js-html:clean

:web-grails:grails-war

|Loading Grails 2.3.8

|Configuring classpath

|Running pre-compiled script

.

|Environment set to development

|Packaging Grails application

|Compiling 10 source files

|Compiling 35 source files

|Compiling 9 source files

|Compiling 5 GSP files for package [webGrails]

|Building WAR file

…Error

|

WAR packaging error: C:\projects\workspace\gradle-multiproject-template\demo-gradle-multiproject\web-js-html\build\libs does not exist.

Picked up _JAVA_OPTIONS: -Duser.home=“C:\dev\user_home”

:web-grails:grails-war FAILED

FAILURE: Build failed with an exception.

  • What went wrong:

Execution failed for task ‘:web-grails:grails-war’.

Process ‘command ‘C:\dev\java\jdk1.7.0_51\bin\java.exe’’ finished with non-zero exit value 1

  • Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 17.802 secs

I’m confused with this output. It seems that :web-js-html gets built first only to be cleaned a little bit later. Then :web-grails gets built, however, due to the fac that :web-js-html was deleted just before, :web-grails obviously fails (“[…] demo-gradle-multiproject\web-js-html\build\libs does not exist”).

How come that this :web-js-html:clean task is invoked after it has been (correctly) built?

My best guess is that it’s due to the way the (third-party) Grails plugin works. ‘web-grails’ depends on ‘web-js-html’, and perhaps the Grails plugin imposes the same dependency on all pairs of equally named tasks. I know too little about the Grails plugin to propose a solution.

Thanks Peter. We switched to a newer version of the plugin

dependencies {

classpath ‘org.grails:grails-gradle-plugin:2.1.0’

}

Now it works fine - seems to indeed have been an issue with the 2.0.1 version.