# testCompile fails for project A importing project B, despite apparent good classpath setup

**URL:** <https://discuss.gradle.org/t/testcompile-fails-for-project-a-importing-project-b-despite-apparent-good-classpath-setup/7129>\
**Category:** Old Forum Archive\
**Created:** [July 23, 2014, 5:15pm UTC](https://discuss.gradle.org/t/testcompile-fails-for-project-a-importing-project-b-despite-apparent-good-classpath-setup/7129 "2014-07-23T17:15:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petula\_Guimaraes](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@Petula\_Guimaraes](https://discuss.gradle.org/u/Petula_Guimaraes)\
**Post date:** [July 23, 2014, 5:15pm UTC](https://discuss.gradle.org/t/testcompile-fails-for-project-a-importing-project-b-despite-apparent-good-classpath-setup/7129/1 "2014-07-23T17:15:00Z")

</div>

I have a project structure as follows:

|-rootProject |------projectA |-----------src/ |-----------config/ |-----------build.gradle |------projectB |-----------src/ |-----------config/ |-----------build.gradle |------projectC |-----------src/ |-----------config/ |-----------build.gradle |------projectD |-----------src/ |------------------build.gradle |-----------config/

All projects have their own classes and tests. projectA, however, depends on B, C and D for its compilation and tests.

The code that needs projects C and D compiles just fine. The code that needs B does not. They are all being imported for compile project and for testCompile project in a similar way.

The failure in A compiling code that depends on B is a funy one, as it does not “like” the reference to a java enum variable reference. if I import the enum only it is fine. But if I import static or just use the enum, that part of the code gets a "cannot find symbol).

Here is my gradle of project B

```gradle
sourceSets {
    main {
    java.srcDirs = ['src/packages']
    resources.srcDirs = [ 'src/packages',
'src/xml', 'src/scripts', 'src/sql', 'src/generic_reports', 'src/config', 'src/asrc'
]
     runtimeClasspath = project.sourceSets.main.compileClasspath +
                    project.sourceSets.test.compileClasspath +
                    fileTree("${buildDir}/resources/test") + fileTree("${buildDir}/resources/main") + fileTree("${projectDir}") +
                    project.sourceSets.test.output + project.sourceSets.main.output
      compileClasspath = compileClasspath + configurations.legacy
       }
   test {
  java.srcDirs = [
'src/tests/packages']
  resources.srcDirs = ['src/tests/packages', 'src/packages', 'src/xml', 'src/scripts', 'src/tests', 'src/testsuite', 'src/sql', 'src/generic_reports', 'src/config', 'src/asrc']
    runtimeClasspath = project.sourceSets.main.compileClasspath +
                    project.sourceSets.test.compileClasspath +
                    fileTree("${buildDir}/resources/test") + fileTree("${buildDir}/resources/main") + fileTree("${projectDir}") +
                    project.sourceSets.test.output + project.sourceSets.main.output
   }
}
  evaluationDependsOn(':projectB)
evaluationDependsOn(':projectC')
evaluationDependsOn(':projectD')
  dependencies {
   compile project(':projectC')
  testCompile project (':projectC').sourceSets.test.runtimeClasspath
 testCompile project (':projectC').sourceSets.main.compileClasspath
                    compile project (':projectD')
 testCompile project (':projectD').sourceSets.test.runtimeClasspath
    compile (project(':projectB')) {
  exclude group: 'fidev', module: 'jfidcore'
 }
    //testCompile project (path: ':stsjava', configuration: 'spi')
//tried, but nothing came out of it
 testCompile project (':projectB').sourceSets.main.runtimeClasspath
    (...
//more on dependencie)
}
  task printClasspath(dependsOn:processResources) {
         println "<><>projectA test compile classpath is:- "
         sourceSets.test.compileClasspath.getFiles().each { file ->
                 println "<><>projectA damn file: \"" + file + "\""
         }
  }

```

I apparently have what I need in the classpath, the annoying enumeration:

```gradle
21:02:05 17:02:04.289 [QUIET] [system.out] <><>projectA damn file: "/var/tmp/pjenkbld/jenkins/workspace/ird-trend-continuous-alternative/ird/trend/alternative/src/projectB/src/packages/com/msdw/ird/stsjava/sts/enumz/ExternalSource.java"

```

The sort of errors I get:

```gradle
16:41:03 12:41:03.138 [ERROR] [system.err] symbol
: variable UTI
16:41:03 12:41:03.138 [ERROR] [system.err] location: class com.msdw.ird.projectA.itm2sts.service.builder.ParameterizedExternalRefFactoriesTest
16:41:03 12:41:03.138 [ERROR] [system.err]
           validateReference(references, UTI, uti.getIdentifier(), _enableUtiBackbridge);
    16:41:02 12:41:02.171 [ERROR] [system.err] symbol
: static PriorUTIPrefix
16:41:02 12:41:02.171 [ERROR] [system.err] location: class com.msdw.ird.projectB.sts.enumz.ExternalSource
16:41:02 12:41:02.171 [ERROR] [system.err] import static com.msdw.ird.projectB.sts.enumz.ExternalSource.PriorUTIPrefix;

```

I am failing to understand what works for the correct import of projects C and D, but not B.

Any suggestions?

Thanks! Petula

---

<div class="post-metadata">

**Author:** ![Petula\_Guimaraes](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@Petula\_Guimaraes](https://discuss.gradle.org/u/Petula_Guimaraes)\
**Post date:** [July 23, 2014, 5:19pm UTC](https://discuss.gradle.org/t/testcompile-fails-for-project-a-importing-project-b-despite-apparent-good-classpath-setup/7129/2 "2014-07-23T17:19:00Z")

</div>

I would stress I have an alledgedly good classpath:

```gradle
sourceSets {
     main {
       java.srcDirs = ['src/packages']
       resources.srcDirs = [ 'src/packages',
'src/xml', 'src/scripts', 'src/sql', 'src/generic_reports', 'src/config', 'src/asrc'
]
        runtimeClasspath = project.sourceSets.main.compileClasspath +
                    project.sourceSets.test.compileClasspath +
                    fileTree("${buildDir}/resources/test") + fileTree("${buildDir}/resources/main") + fileTree("${projectDir}") +
                    project.sourceSets.test.output + project.sourceSets.main.output
       compileClasspath = compileClasspath + configurations.legacy
                   }
    test {
        java.srcDirs = [
'src/tests/packages']
        resources.srcDirs = ['src/tests/packages', 'src/packages', 'src/xml', 'src/scripts', 'src/tests', 'src/testsuite', 'src/sql', 'src/generic_reports', 'src/config', 'src/asrc']
        runtimeClasspath = project.sourceSets.main.compileClasspath +
                    project.sourceSets.test.compileClasspath +
                    fileTree("${buildDir}/resources/test") + fileTree("${buildDir}/resources/main") + fileTree("${projectDir}") +
                    project.sourceSets.test.output + project.sourceSets.main.output
    }
}

```

Again, the code for the dependencies:

```gradle
evaluationDependsOn(':projectB)
evaluationDependsOn(':projectC')
evaluationDependsOn(':projectD')
  dependencies {
    compile project(':projectC')
        testCompile project (':projectC').sourceSets.test.runtimeClasspath
    testCompile project (':projectC').sourceSets.main.compileClasspath
                  compile project (':projectD')
    testCompile project (':projectD').sourceSets.test.runtimeClasspath
    compile (project(':projectB')) {
        exclude group: 'fidev', module: 'jfidcore'
    }
        testCompile project (':projectB').sourceSets.main.runtimeClasspath
        (...
//more on dependencie)
}

```

---

<div class="post-metadata">

**Author:** ![Petula\_Guimaraes](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@Petula\_Guimaraes](https://discuss.gradle.org/u/Petula_Guimaraes)\
**Post date:** [July 28, 2014, 7:52pm UTC](https://discuss.gradle.org/t/testcompile-fails-for-project-a-importing-project-b-despite-apparent-good-classpath-setup/7129/3 "2014-07-28T19:52:00Z")

</div>

I still could not get what is wrong with this particular dependency.

I have tried several approaches such as importing the main or test classpaths (variations on runtime and compile time)

```gradle
compile project(':projectC')
        testCompile project (':projectC').sourceSets.test.runtimeClasspath
    testCompile project (':projectC').sourceSets.main.compileClasspath

```

I also tried a not-very-nice explicit reference to the output folder of the dependency

```gradle
compile project(':projectC')
        testCompile project (':projectC').sourceSets.main.output

```

and the section of sourceSets is now so promiscuous that I even forced the source folders on test and on main\>

```gradle
files(sourceSets.main.java.srcDirs) + files(sourceSets.test.java.srcDirs)

```

It is very strange that all of those yield to my sources of projectC to be in the classpath, but the tests compilation cannot succeed.

Why can’t a normal project dependency be available in the classpath on the moment of test compilation?

Any ideas?

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [July 28, 2014, 8:38pm UTC](https://discuss.gradle.org/t/testcompile-fails-for-project-a-importing-project-b-despite-apparent-good-classpath-setup/7129/4 "2014-07-28T20:38:00Z")

</div>

I recommend to simplify the build until you arrive at a minimal failing example, and then study that. The existing code is too complicated/convoluted to reason about, in particular from a distance.

---

<div class="post-metadata">

**Author:** ![Petula\_Guimaraes](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@Petula\_Guimaraes](https://discuss.gradle.org/u/Petula_Guimaraes)\
**Post date:** [August 4, 2014, 6:46pm UTC](https://discuss.gradle.org/t/testcompile-fails-for-project-a-importing-project-b-despite-apparent-good-classpath-setup/7129/5 "2014-08-04T18:46:00Z")

</div>

I am back to the original situation and I can’t make it work.

sourceSets is very clean:

```gradle
sourceSets {
    main {
    java.srcDirs = ['src/packages']
    resources.srcDirs = [ 'src/packages',
'src/xml', 'src/scripts', 'src/sql', 'src/generic_reports', 'src/config', 'src/asrc'
]
      compileClasspath = compileClasspath + configurations.legacy
              runtimeClasspath += project.sourceSets.main.compileClasspath +
                    project.sourceSets.test.compileClasspath
 }
   test {
  java.srcDirs = [
'src/tests/packages']
   resources.srcDirs = ['src/tests/packages', 'src/packages', 'src/xml', 'src/scripts', 'src/tests', 'src/testsuite', 'src/sql', 'src/generic_reports', 'src/config', 'src/asrc']
    runtimeClasspath += project.sourceSets.main.compileClasspath +
                    project.sourceSets.test.compileClasspath
 }
}

```

dependency is clear:

```gradle
evaluationDependsOn(':projectC')
  dependencies {
 compile (project(':projectC')) {
  exclude group: 'fidev', module: 'jfidcore'
 }
  testCompile project (':projectC').sourceSets.main.compileClasspath
 testCompile project (':projectC').sourceSets.test.runtimeClasspath
   }

```

The problematic class is in the classpath.

```gradle
18:22:56 14:22:54.888 [QUIET] [system.out] <><>service damn file: "/var/tmp/pjenkbld/jenkins/workspace/ird-trend-continuous-alternative/ird/trend/alternative/src/projectC/src/packages/com/msdw/ird/projectB/sts/enumz/ExternalSource.java"

```

Which I logged like this from :

```gradle
sourceSets.test.compileClasspath.getFiles().each

```

And I still get cannot find symbol in any test that included this referred class.

Any ideas why it does not work for this class to be found on compileTest?

---

<div class="post-metadata">

**Author:** ![Petula\_Guimaraes](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@Petula\_Guimaraes](https://discuss.gradle.org/u/Petula_Guimaraes)\
**Post date:** [August 4, 2014, 6:57pm UTC](https://discuss.gradle.org/t/testcompile-fails-for-project-a-importing-project-b-despite-apparent-good-classpath-setup/7129/6 "2014-08-04T18:57:00Z")

</div>

Thanks. I provided new snippets

---

<div class="post-metadata">

**Author:** ![Petula\_Guimaraes](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@Petula\_Guimaraes](https://discuss.gradle.org/u/Petula_Guimaraes)\
**Post date:** [August 5, 2014, 3:43pm UTC](https://discuss.gradle.org/t/testcompile-fails-for-project-a-importing-project-b-despite-apparent-good-classpath-setup/7129/7 "2014-08-05T15:43:00Z")

</div>

I am totally lost here. I replaced the testCompile dependencies above with something more elaborate, trying to make a separate configuration with this dependency that does not want to be resolved and IT STILL DOES NOT WORK.

Am I so offtrack here?

That is what I did to the project I depend upon, projectC

```gradle
configurations {
    spi
}
    dependencies {
...
}
  task spiJar(type: Jar) {
        baseName = 'projectc-spi'
        dependsOn classes
        from sourceSets.main.output
        include('com/msdw/ird/**')
    }
  artifacts {
 spiJar
}

```

and how I am using it

```gradle
testCompile project (path: ':projectC', configuration: 'spi')

```

I am sure those thing should work on a “by the book” analysis. I still see all I need in the classpath but somehow my compilation goes somewhere else to resolve my code?

---

<div class="post-metadata">

**Author:** ![Petula\_Guimaraes](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@Petula\_Guimaraes](https://discuss.gradle.org/u/Petula_Guimaraes)\
**Post date:** [August 5, 2014, 9:07pm UTC](https://discuss.gradle.org/t/testcompile-fails-for-project-a-importing-project-b-despite-apparent-good-classpath-setup/7129/8 "2014-08-05T21:07:00Z")

</div>

FIXED

it turned out all this time I had a nested dependency that I did not suspect was causing the issue. One of my literally hundreds of dependencies was bringing in a jar that contains an older version of this Enum. Nasty.

Therefore, I can only say the approaches above work.

However, not sure why I am not being successful in removing this dependency via configurations.exclude. It always end up in the classpath. My workaround on this is

```gradle
compileTestJava {
 classpath = classpath.filter {
   it.name != 'oldProjectC.jar'
 }
}

```

Anyways, I guess this would be subject of another thread. For now it is ok, tests are compiling and executing.

Cheers, Petula
