Configure JVM Test Suite to build/run several suite depending on different artefacts (Multi-Project)

Hi,

I have two projects, A and B.
A has three sourceSets. The default one contains an API and the two additional sourceSets contain two different implementations of this API. It is declared as follow using builde.gradle :

plugins {
	id 'java'
}

sourceSets {
    impl1 {
        java { 
			srcDir "src/impl1/java/"
			compileClasspath += sourceSets.main.output
			runtimeClasspath += sourceSets.main.output
		}
    }
	impl2 {
		java {
			srcDir "src/impl2/java/"
			compileClasspath += sourceSets.main.output
			runtimeClasspath += sourceSets.main.output
		}
	}
}

task impl1(type: Jar) {
	from sourceSets.impl1.output
	archiveFileName = "A-impl1.jar"
}

task impl2(type: Jar) {
	from sourceSets.impl2.output
	archiveFileName = "A-impl2.jar"
}

jar.dependsOn impl1, impl2

It produces three jars (A.jar , A-impl1.jar and A-impl2.jar).

Enters the second project, B.
This project is meant to implement (and run) the tests. The tests relies on the API defined in the project A. I need to compile/run the tests for the two implementations defined in A, impl1 and impl2.

The idea is to use JVM Test Suite to define two suites : one using the implementation provided in A-impl1.jarand the other using the one provided byA-impl2.jar.

So far, I’ve defined the following build.gradle for project B:

plugins {
	id 'java'
	id 'jvm-test-suite'
}

testing {
	suites {
		configureEach {
			useJUnitJupiter()
			dependencies {
				implementation 'org.junit.jupiter:junit-jupiter:5.10.2'
				implementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
				implementation project(':A')
				runtimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.2'
			}
		}

		impl1Test(JvmTestSuite) {
			dependencies {
				// How to manage runtimeOnly and/or implementation
			}
		}

		impl2Test(JvmTestSuite) {
			dependencies {
				// How to manage runtimeOnly and/or implementation
			}
		}
	}
}

// ... other convenience declarations (logging, task dependencies)

The thing is that I have hard time to specify the dependencies to the artifacts produces in project A (A-impl1.jar and A-impl2.jar).

The plugin dependencies section is a bit different than the “regular” one. For example, I could add project-wise dependency in B as :

dependencies {
	implementation project(':A').sourceSets.impl2.output
}

In that case, I don’t even have to care about the produced artifacts. Everything compile and run BUT only for one implementation only.

If I try to set the same dependency in the test suites, I get errors as sourceSets is not recognized. Same goes for artifacts and such.

So, where am i wrong here ? Is there a way to refer to artifacts and/or sourceSets from another project ?

Thx.

There are ways.
And you should not even consider thinking about any of them, as it is an extremely bad idea.
If you want to use something from another project, you need to do it properly as shown on How to share outputs between projects

So for example create feature variants from your source sets, or at least outgoing configurations.

Or use separate projects instead of source sets. One for the API and one for each of the impls.