# Eclipse (2023-12) + Buildship - Incorrect classpath when importing test utils from project library

**URL:** https://discuss.gradle.org/t/eclipse-2023-12-buildship-incorrect-classpath-when-importing-test-utils-from-project-library/47970
**Category:** Buildship
**Created:** [March 15, 2024, 9:34am UTC](https://discuss.gradle.org/t/eclipse-2023-12-buildship-incorrect-classpath-when-importing-test-utils-from-project-library/47970 "2024-03-15T09:34:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Simone\_Vratogna](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/simone_vratogna/32/342_2.png) [@Simone\_Vratogna](https://discuss.gradle.org/u/Simone_Vratogna)
#### Post date: [March 15, 2024, 9:34am UTC](https://discuss.gradle.org/t/eclipse-2023-12-buildship-incorrect-classpath-when-importing-test-utils-from-project-library/47970/1 "2024-03-15T09:34:42Z")

</div>

Recently we made the big jump from java 8 to java 20, gradle 4.6 to gradle 8.6, and eclipse Neon (2018) to Eclipse 2023.

This is to say that the project structure is a bit old and I made a big jump between eclipse versions.

The problem is only in eclipse: from command line everything is ok.

Basically I have 2 libraries.

- Lib2 contains some code and some test utils. These test utils are classes that should be made available to other project to instrument their tests.
- Lib3 has some code (using Lib2) and tests that uses the test utils from Lib2

When the Lib3 project is imported/refreshed, eclipse generates a wrong classpath, basically it includes Lib2 in the following way:

[![enter image description here](https://global.discourse-cdn.com/gradle/original/2X/9/90edb508d873819d526810b6f74bad06caa3fd94.png)](https://i.stack.imgur.com/v9geX.png)

As you can see it’s **only visible to tests sources** BUT **withtout test code**.  
The result is that it’s totally useless, since I need part of it to instrument the tests and part of it for the code. **So, all the import fails** (in main and in test).

Relevant gradle configuration:

Lib2:

```gradle
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'eclipse'

//Test Utils Part
sourceSets {
  testUtils {
    compileClasspath += sourceSets.main.output
    runtimeClasspath += sourceSets.main.output
  }
  test {
    compileClasspath += sourceSets.testUtils.output
    runtimeClasspath += sourceSets.testUtils.output
  }
}

/*
 * To compile testUtils sourceSet we need to exends the configuration for the 'main' sourceSet.
 * And, since we define dependencies only for testUtils, test must have to extends from it.
 */
configurations {
    testUtilsImplementation.extendsFrom implementation
    testUtilsRuntime.extendsFrom runtime
    testCompile.extendsFrom testUtilsImplementation
    testImplementation.extendsFrom testUtilsImplementation
}

configurations {
    testUtilsArtifacts.extendsFrom testUtilsImplementation
}

task testUtilsJar(type: Jar) {
    archiveClassifier.set("test")
    from sourceSets.testUtils.output
}

artifacts {
    testUtilsArtifacts testUtilsJar
}

// End test utils part

```

Lib3:

```gradle
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'eclipse'

repositories {
     mavenCentral()
}

dependencies {
	  /*Leo*/
	api project(":Lib2")
    testImplementation project(path: ":Lib2", configuration: 'testUtilsArtifacts')    
 }

```

and settings.gradle

```gradle
include (":Lib2")
project(":Lib2").projectDir = file("../Lib2")

```

It seems a pretty basic configuration, I don’t understand why it doesn’t work anymore. I believe that I should tweak something using the eclipse plugin but I have no idea where to start.

---

<div class="post-metadata">

### Author: ![Simone\_Vratogna](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/simone_vratogna/32/342_2.png) [@Simone\_Vratogna](https://discuss.gradle.org/u/Simone_Vratogna)
#### Post date: [March 19, 2024, 9:30am UTC](https://discuss.gradle.org/t/eclipse-2023-12-buildship-incorrect-classpath-when-importing-test-utils-from-project-library/47970/2 "2024-03-19T09:30:14Z")

</div>

I can add, that the big jump in java/eclipse version has nothing to do with the problem. What I’m showing is what happens with two brand new projects

---

<div class="post-metadata">

### Author: ![oleosterhagen](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/oleosterhagen/32/11914_2.png) [@oleosterhagen](https://discuss.gradle.org/u/oleosterhagen)
#### Post date: [March 19, 2024, 7:53pm UTC](https://discuss.gradle.org/t/eclipse-2023-12-buildship-incorrect-classpath-when-importing-test-utils-from-project-library/47970/3 "2024-03-19T19:53:15Z")

</div>

In order to expose test classes to dependent projects, you have to append this to your `build.gradle` of **Lib2** :

```gradle
eclipse {
    classpath {
        containsTestFixtures = true
    }
}

```

After a refresh the property _without test code_ for the dependency from Lib3 to Lib2 should disappear.

Unfortunately, the other property _Visible only for test sources_ requires an ugly workaround in `build.gradle` of **Lib3** :

```gradle
eclipse {
    classpath {
        file {
            whenMerged {
                entries.findAll { it.path == '/Lib2' }.each { it.entryAttributes['test'] = 'false' }
            }
        }
    }
}

```

See also [EclipseClasspath](https://docs.gradle.org/current/dsl/org.gradle.plugins.ide.eclipse.model.EclipseClasspath.html) in the DSL reference.

---

<div class="post-metadata">

### Author: ![Simone\_Vratogna](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/simone_vratogna/32/342_2.png) [@Simone\_Vratogna](https://discuss.gradle.org/u/Simone_Vratogna)
#### Post date: [March 21, 2024, 9:47am UTC](https://discuss.gradle.org/t/eclipse-2023-12-buildship-incorrect-classpath-when-importing-test-utils-from-project-library/47970/4 "2024-03-21T09:47:08Z")

</div>

Great, it works, thanks!
