4

I have Project A and project B

Project A unit-testings (under the tests dir) need to use resources files which under Projects B main/resources dir.

gradle.build on Project A:

dependencies {
..    testCompile project(':web')
}

gradle.build on Project B:

task testJar(type: Jar) {
    classifier 'resources'
    from sourceSets.main.resources
}

still failing. i am not sure what am I missing?

Thank you, ray.

rayman
  • 20,786
  • 45
  • 148
  • 246

1 Answers1

6

When you add a dependency on a project like this:

testCompile project(':B')

you're depending on the default artifact produced by project B, which is usually the default jar. If you want to depend on a custom jar, something like a test jar, or a resource jar, or a fat jar instead, you have to explicitly specify that. You can add custom artifacts to configurations, and depend on the configuration instead, as shown below:

in B's build.gradle:

configurations {
  foo
}

task testJar(type: Jar) {
    classifier 'resources'
    from sourceSets.main.resources
}

artifacts {
  foo testJar
}

and then use it in A as:

dependencies{
    testCompile project(path: ':B', configuration: 'foo')
}

To verify, you can add this task to A:

task printClasspath()<<{
    configurations.testCompile.each{println it}
}

which prints:

${projectRoot}\B\build\libs\B-resources.jar
RaGe
  • 22,696
  • 11
  • 72
  • 104
  • what would u modify if i wanted instead of taking resources of project B but it's test's resources? – rayman Apr 18 '16 at 19:13