testCompile with other project dependency seems to include other project classes

Hi,

Forgive me for the title, but I’m not sure how I could word it succinctly :slight_smile:

Gradle 1.3 Java 1.7u10 Xubuntu 12.10.

Project A has a definition containing:

task createTestJar(type: Jar) {
    classifier = 'tests'
    from sourceSets.test.output.classesDir
}
  configurations {
    tests
}
  artifacts {
    tests createTestJar
}

Then, I have this defined as an intra-project dependency:

project(':b') {
    dependencies {
        testCompile project(path ':a', configuration: 'tests')
    }
}

Let’s pretend there is a class called Widget.class that lives in A/build/classes/test.

When I run

gradle :b:test

I find that Widget.class from A gets copied into B/build/classes/test.

This is not what I desire, I only want B to depend on the test jar (containing the test classes) and not copy the test classes from A into B!

I’m obviously doing something wrong! :slight_smile: Any help would be appreciated.

Thank you.

I find that Widget.class from A gets copied into B/build/classes/test.

Can you double-check that you don’t have some other code that’s responsible for this? Or maybe ‘:b’'s ‘src/test/java’ also has a ‘Widget’ class?

Hi,

Checking first point.

As for the second point, I can confirm that Widget.class only exists in A, not B (although B has a test compile and a test runtime dependency on A - hence the desire to have the test Jar of A available).

Hi,

Yes, it was indeed my fault. I had this:

processTestResources {
    ext.testProperties = new Properties()
      ['a', 'b'].each { database ->
        testProperties.setProperty('targetDatabaseUrl_' + database, targetDatabaseUrl + '/test_' + database + '?allowMultiQueries=true&characterEncoding=utf8')
        testProperties.setProperty('targetDatabaseUsername', targetDatabaseUsername)
        testProperties.setProperty('targetDatabasePassword', targetDatabasePassword)
    }
         from(sourceSets.test.resources.srcDirs) {
        include '**/*.properties'
        filter(ReplaceTokens, tokens: testProperties)
    }
         from(sourceSets.test.resources.srcDirs) {
        exclude '**/*.properties'
    }
   }

whereas, I should have also been exluding Java source files, thus:

processTestResources {
    ext.testProperties = new Properties()
      ['a', 'b'].each { database ->
        testProperties.setProperty('targetDatabaseUrl_' + database, targetDatabaseUrl + '/test_' + database + '?allowMultiQueries=true&characterEncoding=utf8')
        testProperties.setProperty('targetDatabaseUsername', targetDatabaseUsername)
        testProperties.setProperty('targetDatabasePassword', targetDatabasePassword)
    }
         from(sourceSets.test.resources.srcDirs) {
        include '**/*.properties'
        filter(ReplaceTokens, tokens: testProperties)
    }
         from(sourceSets.test.resources.srcDirs) {
        exclude '**/*.properties'
        exclude '**/*.java'
    }
   }

Thanks for the hint! :slight_smile: