Gradle batch task calling subproject and other tasks in order

I am writing a gradle 1.4 build file for a multimodal project. So, there is root build.gradle that defines something like:

subprojects { apply plugin: 'java' ... 

which defines the build task for all submodules. Submodules are included in settings.gradle , and each module has its own build file with certain dependencies.

Everything is still in the book :) Now, in the main assembly file, I added some additional tasks for the project area, such as: aggregateJavadoc (collects all javadocs into one) or bundleJar (creates a socket bank of all classes), etc. . Each of them works when called manually.

Now I need a release task that will

  • build all submodules (as called from the command line - that means I donโ€™t want to manually write execute () for each submodule)

  • call additional tasks (using execute (), I guess).

I tried dependOn , but the order of the listed tasks is not respected. In addition, the dependent modules are apparently executed after the launch task. I tried several other ideas and could not.

Question: what would be the best way to create such a batch task, which should cause something on all submodules and additionally perform several more tasks? What would be the best gradle other solution? Thanx!

+8
gradle
source share
1 answer

It so happens that this can be solved with a simple dependency management.

So, we have many modules. Now let's create additional tasks that depend on the modules under construction:

 task aggregateJavadoc(type: Javadoc) { dependsOn subprojects.build task bundleJar(type: Jar) { dependsOn subprojects.build 

Finally, our release task will look something like this:

 task release() { dependsOn subprojects.build dependsOn aggregateJavadoc dependsOn bundleJar ... } 

Subprojects will be built first; not because it is listed first, but because additional tasks depend on the building. Ordering an additional task does not matter. This is most important to me.

EDIT if one of your subprojects (i.e. modules) is a module other than java, then you will have a problem creating this project. I do this to group submodules, for example:

 def javaModules() { subprojects.findAll {it.name.contains('jodd-')} } 

and then instead of subprojects , use javaModules everywhere! For example:

 configure(javaModules()) { apply plugin: 'java' ... 

and

 task prj { dependsOn javaModules().build } 

btw, I use this 'dummy' prj for dependsOn for all of these additional projects that are build dependent to prevent repetition.

+9
source share

All Articles