Extending the 'build' task with a plugin in a subproject

Hello everyone,

I have a multiproject build whose subprojects are composed primarily of scripting languages. Therefore, in most projects there is no actual compilation to be done when building the project. However in one leaf project, there is some java that needs to be compiled. Since I’ve defined the build task in the parent project, the “apply pluing: java” doesn’t seem to be working correctly.

In the parent I have the following build script:

subprojects {
    task build {
            dependsOn "buildDnaProject"

    task buildDnaProject {
            dependsOn "copyQ"
            dependsOn "copyConfig"
            dependsOn "copyLib"

    task copyQ(type: Copy) {
            description "Copies q scripts from src/main/q to the build directory"
            from "src/main/q"
            into "$buildDir/src/q"

    task copyConfig(type: Copy) {
            description "Copies config files from src/main/config to the build directory"
            from "src/main/config"
            into "$buildDir/etc"

    task copyLib(type: Copy) {
            description "Copies lib files from lib to the build directory"
            from "lib"
            into "$buildDir/lib"

And in the leaf project I have a build script with one line: apply plugin: “java”

When I run gradle build, it performs all the copy tasks as defined in the parent, but the leaf project with java is not compiled or tested. Is there a way that I can get the leaf project to “extend” the currently defined build task and also do java compilation?

Snippet of the output from my build:

:dnaProjects:yieldDatabase:copyLib UP-TO-DATE

do you have a reproducable small example to share?

Attached an example project.

gradle-example.zip (9.0 KB)

Following up on this, I was able to circumvent the issue by using the existing parent build task definition and adding the appropriate dependencies for the java build task in the leaf project.

apply plugin: "java"

build.dependsOn "check"
build.dependsOn "assemble"

Obviously this is not ideal, because the dependencies for the java build task could be changed in the future (or implement some logic) but so far this works with Gradle 2.4.

1 Like