buildship
buildship copied to clipboard
Test dependencies between modules not working anymore in Gradle 6.7
Let's say I have 2 Gradle projects called "project-base" and "project-extension".
I want to be able to see the classes defined in the src/tests/java of "project-base" inside the src/tests/java of "project-extension", to be able to use common code between the test of the projects.
In order to do that, I put this in "project-extension":
dependencies { testImplementation project(path: ':project-base', configuration: 'testArtifacts')
This used to work until Gradle 6.6.1. But now I tried to switch to Gradle 6.7 and it does not work in Eclipse. Eclipse will be able to navigate to the classes in "project-base" but will still show them in red and refuse to compile, saying that it cannot resolve the dependencies.
Note that this still works file in IntelliJIdea, even for Gradle 6.7, which makes me believe that it has to do with Buildship not supporting this feature for Gradle 6.7 correctly.
Just wanted to cheer in: it also seems to have stopped working when using the java-test-fixtures plugin as explained in the docs here.
Eclipse error log showing nothing.
FYI: I guess this is related to https://github.com/gradle/gradle/issues/14932, which has been fixed in Gradle 6.8. I can confirm that it works again with STS 4.9.0 and Gradle 6.8.
Can be closed for me.
For me the problem still exists after updating to gradle 6.8.
For example, here the dependency definition:
testImplementation project(path: ':server', configuration: 'testOutput')
Leads to errors:
[...]/URLRepositoryITest.java|5 col 15| The import io.crate.testing cannot be resolved
[...]/URLRepositoryITest.java|6 col 15| The import io.crate.testing cannot be resolved
If I change the gradle wrapper to 6.6.1 and load the project, the errors disappear.
I am also affected by this problem.
me too :/
As info for others: The compile issue mentioned in this issue could be solved by migrating to use the java-test-fixtures plugin, but then you might run into https://github.com/microsoft/vscode-java-test/issues/1073 next.
We are encountering this issue, too, using recent Eclipse and gradle 6.8.3.
Following up on reporters' and @donat 's comments to gradle/gradle#12354 and #1009 we created a small project to show the behavior in enqueue/buildship-reproducer.
If you can tell us better way to model these dependencies, which is compatible with Eclipse, we will see if we can adjust our projects. For now, Eclipse is unusable for some projects that rely on this kind of dependency model, which works fine using gradle proper.
still happens with gradle 6.9.1 and 7.3
Having upgraded to gradle 7.3, this problem still occurs, forcing us to import our project with gradle 6.6.1, which in turn prevents us from using any nice features in gradle. Is there anything we can do (including paid support...) to have someone look into this problem and provide a fix?
Same problem here. Does someone have found a workaround for Gradle 7.3 ?
FWIW we have solved this problem ultimately by using the testFixtures plugin which forced us to separate real test code from test infrastructure code. Unfortunately using the testFixtures plugin not only meant a lot of work to get our existing code base aligned it also produced new problems with other plugins (e.g. the JavaFX Plugin) that were not prepared for testFixtures. We finally managed to migrate to testFixtures but the transition process was a huge headache :-(.
@ValeriuIonutIocsa @netmikey @mfussenegger @effad @gbu-censhare @enqueue @stefanrybacki @ptrussart I'm working on improving test sources separation. Would you mind trying https://github.com/gradle/gradle/pull/19310? Any feedback is appreciated.
You can evaluate my changes by using this snapshot release: https://services.gradle.org/distributions-snapshots/gradle-7.4-branch-donat_eclipse_test_sources_and_deps_take_2-20211222124805+0000-bin.zip
The most important changes are the new testSourceSets and testConfigurations properties on EclipseClasspath: https://github.com/gradle/gradle/pull/19310/files#diff-a06321f72727bb53bd4f6051b21f9368d255beae6df48e3c720464cd7cc43441
I tried your snapshot, but a "gradle refresh" in eclipse yields the error message "java.lang.IllegalArgumentException: '7.4-branch-donat_eclipse_test_sources_and_deps_take_2-20211222124805+0000' is not a valid Gradle version string (examples: '1.0', '1.0-rc-1')" Can I do anything as a workaround to test the snapshot?
Yes, you can check out my feature branch and build a local distribution with the following command:
./gradlew install -Pgradle_installPath=/path/to/dist
Please fix this. https://github.com/gradle/gradle/issues/12354 broke our builds (Gradle 6.9.2, worked in 6.0.1). You cannot simply set without_test_code = true everywhere, when the consumer explicitly includes the dependency. Our builds work as intended in plain Gradle or IntelliJ.
We've done improvements on the Eclipse test sources in the upcoming Gradle 7.5 release: https://github.com/gradle/gradle/pull/19310 Can someone here confirm that the changes resolve this issue? To that, you can use the latest 7.5 snapshot.
@donat,
Can someone here confirm that the changes resolve this issue? To that, you can use the latest 7.5 snapshot.
Testing 7.5 release nightly seems to break cross-project dependencies even between src/main/ directories, here.
Background: Thanks to the hints here, I also solved this by porting our 20-odd projects to use java-library and java-test-fixtures plugins. (A few days of distraction, but happy with the resulting structure.)
To test the above what I did was:
- Rewind git history to before this big restructuring
- Upgraded Gradle 7.3.1 > 7.4.2 (Setting the "Specific Gradle version" in the root project's Property dialog)
/test/code is sad (5130 errors) - errors on name of any test-classes from referenced projects- Everything else happy: production code builds & runs.
- Upgraded Gradle > 7.5-20220425235710+0000:
- Everything is sad. Errors upon any class from a referenced project, even those in
src/main/directories - Only the lowest level projects (those without any other Eclispe-Project dependencies) compile
- Everything is sad. Errors upon any class from a referenced project, even those in
Everything in the Project's Java classpath (etc) dialogs looks fine to me. Please let me know if there's more troubleshooting steps I can help with.
@donat, I think I've got some further clues. I suspect my issue relates to a Project pse-junit which containing a bunch of our own JUnit 4/5 extensions. I.e. the code for these is in src/main (plus they also have tests in src/test). Most other projects include this one.
So I focused on trying to get 2 Projects to build:
- common-util: (lowest-level) and
- 'expression' (depends on 1.)
Looking in the "Projects and External Dependencies" Of Project 'expression', its entry for 'common-util' says:
- Visible only for test sources: Yes - non modifiable
- Without test code: Yes - non modifiable
and 'expression' contains build errors for classes defined in 'common-util'. However, removing the dependency on pse-junit from both projects fixed these, making src/main error-free again. (But of course src/test has errors due to missing pse-junit.)
Please note even this small success with src/main was only achieved in the historic code, prior to the move to java-test-fixtures and with a fresh Eclipse workspace. (This was to match what I understood you requested to test.)
By contrast if use the latest code (using java-test-fixtures) and switch it to 7.5-20220425235710+0000 it does not work: 'expression' always sees 'common-util' as "only for test sources" and I can't figure out how to fix that.
(Incidentally both these projects expose "test fixtures", now via a src/testFixtures/ directory. I'm not 100% clear whether I need to add:
eclipse.classpath {
containsTestFixtures = true
}
or whether that's just necessary for the "old" version where those files were just bundled inside src/test/ ? But I guess this is not the first problem that needs solving.
The primary problem I think is: how to get these projects compiling in Gradle 7.5 when the pse-unit project is still included?
@donat , I tried gradle 7.5-rc-3, but get the same results as @lukeu . Projects that contain both testfixtures and main code are included as dependencies "Visible only for test sources: Yes - non modifiable". Projects depending on the main classes are not compiling.
I am encountering this problem in VS Code (1.72.2) and using Language Support for Java.
Gradle (7.5.1) compiles the project just fine. It's just VS Code which shows a bunch of (main classes) cannot be resolved error messages.
Cloning and opening this project in VS Code results in the above error message: https://github.com/joel-jeremy/externalized-properties
Here's a description of what the project structure and the issue looks like:
externalized-properties-core- This project applies the
java-test-fixturesplugin and has some test fixture classes undersrc/testFixtures
- This project applies the
externalized-properties-git- This project depends on
externalized-properties-coreand its test fixtures (see build.gradle)
- This project depends on
When opening a java file (e.g. GitResolver) in externalized-properties-git project, it says that the classes from externalized-properties-core cannot be resolved.
I'm trying to migrate a maven project to gradle 7.6.1 but now blocked by this issue. Has this issue been fixed or is there any easy workaround?
https://github.com/gradle/gradle/issues/12354 @lionelcao Doing the opposite of what was proposed for 12354 seems to work with minimal effort. eclipse.classpath.file.whenMerged { entries.findAll { it instanceof org.gradle.plugins.ide.eclipse.model.ProjectDependency } .each { it.entryAttributes['without_test_code'] = 'false' } }