I have imported a gradle project in eclipse. There...
# community-support
f
I have imported a gradle project in eclipse. There are two modules A and B. A has dependency on test jar of B something like below testImplementation project(path: 'commonplugins:common.domain', configuration: 'tests') build is getting successfull but eclipse is showing errors for imports of classes coming from test jar of B. test jar configuration in B (commonpluginscommon.domain) is done like this configurations { tests } tasks.register('testsJar', Jar) { archiveClassifier = 'tests' from(sourceSets.test.output) } artifacts { archives(tasks.named("testsJar")) tests testsJar } Why eclipse is failing to resolve?
v
You should maybe use the Java Test Fixtures instead to share test code between projects. 🤷‍♂️
f
Do you have any example to implement. Is this can be done with gradle 8.13?
v
Sure, test fixtures are there for quite some time already: https://docs.gradle.org/current/userguide/java_testing.html#sec:java_test_fixtures
f
Ok I tried the Java Test Fixtures and yes errors got resolved. But there is an issue while I am trying to execute the unit tests from option Run As -> Junit Test in eclipse 2024-06, it is not executing test cases and I am seeing something like this
Intrestingly now build fails while running gradle clean build. 🙃 why so?
v
Probably because you are not running any tests and are using Gradle 9 where this is an error if you have sources but no executed tests.
Why no tests are executed I can hardly guess from the almost no information you provided. Did you try to share the actual tests from one project to the other? Then you might configure something to detect tests also in dependencies or something like that iirc.
f
I am using gradle 8.13. There are two modules A and B. A has dependency on test jar of B something like below testImplementation (testFixtures(project(path: ':A'))), A has some utility class in src/test/java, So while running JUNit Test in a test class available in src/test, it is using the functionallity from B's src/test/java only. Eclipse is not giving any logs while this no execution, just finishing in few ms.
v
Your description is a bit blurry, can you show an MCVE?
f
Module A common.domain plugins { id 'java-library' id 'java-test-fixtures' } A has src/test/java/com/ex/unit/BaseUnitTestCase.java doesnot have test method only some utility mettods commonly used in overall project. Module B service.impl plugins { id 'java-library' id 'java-test-fixtures' } dependencies { testImplementation(testFixtures(project(':common.domain'))) } B has src/test/java/com/ex/services/impl/SwxifaceStatsServiceTest.java is a test class public class SwxifaceStatsServiceTest extends BaseUnitTestCase { @Test public void testImportQueueStatsForMultipleIntervals() { ... } But while running Run As -> Junit Test in class SwxifaceStatsServiceTest is not executing test method testImportQueueStatsForMultipleIntervals only says Runs: 0/0 Hope this make some sense.
v
B should not even compile if you try to use classes from A test fixtures, because the classes in A should be in
src/testFixtures/java
, not
src/test/java
And B does not need the test fixtures plugin, only the plugin providing the test fixtures needs it
Also, try first make the tests run through Gradle, then you know the setup is right, then try whether it works in Eclipse after the working build is synced
f
It's going little bit confusing. Are you saying to create src/testFixtures/java manually in place of src/test/java or the plugin itself should take care.
v
You.
f
What can be the reason that it is not executing form Sun As -> JUnit Test ? Maven always does this successfully and people who have this habit might feel uncomfortable.
v
I don't know what that does, I don't touch Eclipse with a five foot pole if I can avoid it. But if it is not even running via pure Gradle, I would not expect it to work in Eclipse either. Same for Maven, if it does not work there, I would expect it to also not work in Eclipse.
f
with Gradle Test it is able to execute
v
With the A sources in
src/test/java
instead of
src/testFixutres/java
? As I said, that should not even compile given the information you provided so far. You really need to provide an MCVE probably.