Java Dude
Java Dude

Reputation: 596

Gradle task execution order

I have simple task that should copy my resources before the classes task.

task copyJsMocks(type:Copy) {
    println "Is java script mocks needed: " + project.hasProperty('mockServices');

def mockSrc = projectDir.toPath().toString() + "/src/test/resources/site/services";
def mockDst = buildDir.toPath().toString() + "/resources/main/site/services";

if (project.hasProperty('mockServices')) {
    from mockSrc;
    into mockDst;
}

classes {
   dependsOn copyJsMocks;
}

...But according to the logs this task is executed at the beginning.

Log

.....
Is java script mocks needed: true
:phantomJsStop
:clean
:cleanEnonicDeploy
:compileJava
:compileGroovy UP-TO-DATE
:processResources
:classes

How I can fix it?

Upvotes: 0

Views: 754

Answers (1)

David M. Karr
David M. Karr

Reputation: 15235

Read the Gradle user guide PDF that comes with the distribution.

You'll learn that tasks are executed in two phases, the "configuration" phase and the "execution" phase. That println statement executed in the configuration phase, and you don't control the ordering of when tasks are executed in the configuration phase.

Upvotes: 1

Related Questions