Run task after subprojects has been built

Hi,

I’m struggling with following scenario. I have several subprojects which use ‘java’ plugin. settings.gradle

include 'subA', 'subB', 'subC'

Root project has single task called ‘build’, but it doesn’t use ‘java’ plugin.

task build() << {
    dependsOn subprojects.build
    println 'I should be visible after subprojects are built'
}

If I run ‘build’ task from root project, Gradle will call ‘build’ tasks on subprojects, resulting to following output (pseudo)

I should be visible after subprojects are built
:subA:compileJava
:subA:processResources
:subA:classes
:subA:jar
:subB:compileJava
... etc. ...

What I don’t understand is, why is the “I should be visible after subprojects are built” message printed BEFORE subprojects are built? Can anyone provide some hints about this? I’ve went through documentation, but I didn’t find anything useful there.

Thanks in advance

You have ‘dependsOn’ in a task action, not in your task configuration. (The ‘<<’ operator is shorthand for task.doLast {}). So your root project build task doesn’t do what you expect.

task build {
    dependsOn subprojects.build
    doLast {
        println 'here'
    }
}
1 Like

Well, that actually doesn’t work. I get following error message:

Could not find property 'build' on project ':subA'.

I saw your solution on several other forums/webs though. But this error line confuses me. I’m using Gradle 1.4, perhaps it’s something that had been changed in this release?

Hey Matthew, the problem is the evaluationorder of your projects. can you add this to your rootproject build script

evaluationDependsOnChildren();

and check if that solves your problem?

cheers, René

1 Like

Hi Rene,

It’s still doesn’t work with “evaluationDependsOnChildren();” in root project. However, I think I didn’t express my problem clearly. What I’m trying to do here, is to create sort of “aggregation” task which would simply take results of sub-project task execution, and aggregate them into one place. At the same time, I wanted to leverage “build” task name, which by default, gradle runs also on all sub-projects. Sub-projects are java projects, so each have it’s own “build” task.

Therefore, I really don’t want to declare this task in configuration phase. Can you please advice me some clever way how to achieve this?

Hi,

I just read whole topic and I realized, that Daz’s answer is working for me. I also need to add line

evaluationDependsOnChildren();

into my build script. Sorry guys. I had to take a look at this with “fresh eyes” this morning. Thanks for all your answers.