Dependencies on source set of different projects


(Thiago Berne) #1

I’m working in a multiproject system (with 40+ subprojects). Each subproject has its own layout (most follows a common layout, but some differ). Among the subprojects I have these two:

  • testjunit

    • sourceSets
      • lptfExperimental
      • other source sets
  • basicservices

    • sourceSets
      • testacceptance
      • other source sets

I need to make the source set basicservices-testacceptance depend on the output of source set testjunit-lptfExperimental.

I tried to do:

dependencies{
    testacceptanceCompile project(':testjunit').sourceSets.lptfExperimental.output
}

And

dependencies{
    project.parent.subprojects.each{prj ->
        if(prj.name == "testjunit")
            testacceptanceCompile prj.sourceSets.findByName('lptfExperimental').output
}

But in both cases I receive the following error:

FAILURE: Build failed with an exception.

Where: Script ‘C:\Lumis\Development\Lumis_PortalJava\defaults.gradle’ line: 144

What went wrong: A problem occurred evaluating script. Could not find property ‘lptfExperimental’ on SourceSet container.

Just an extra info: this dependency is declared in a file named defaults.gradle that is applied in build.gradle of project basicservices.

/defaults.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
...
sourceSets {
    ...
    // test acceptance
    testacceptance{

        java{
            srcDir 'test/acceptance/src/java'
        }

        resources {
            srcDir 'test/acceptance/src/java'
        }
    }
    ...
}

// default dependencies
dependencies{
    testacceptanceCompile project(':testjunit')
    testacceptanceCompile project(':testjunit').sourceSets.lptfExperimental.output
}
...

/testjunit/build.gradle:

...
sourceSets{
    ...
    lptfExperimental{

    java {
        srcDir 'lptf-experimental/src/java'
    }

    resources {
        srcDir 'lptf-experimental/src/java'
    }
}
...

/basicservices/build.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
apply from: '../defaults.gradle'

dependencies{
    ...
    compile project(':testjunit')
    ...
}

(Ed Mitchell) #2

Try defining an artifact for lptfExperimental source set:

configurations {
    lptfExperimental
}

task lptfExperimentalJar(type:Jar) {
    from sourceSets.lptfExperimental.output
}

artifacts {
    lptfExperiemental lptfExperimentalJar
}

Then in basicservices/build.gradle:

dependencies {
    compile project(path: ':testjunit', configuration: 'lptfExperimental')
}

(Basil Peace) #3

What is the difference if I use lptfExperimentalRuntimeElements configuration?