Declaring a dependency onto the test sources of a sibling project

I have a gradle multi-module project which was using a very old version of gradle, now I’m upgrading to gradle 8 and kotlin buildscripts.

I’m facing the issue that the old gradle config used the following to declare a dependency between test sources:

testImplementation project(':my.sibling.project').sourceSets.test.output

At least with the kotlin DSL, that no longer works. I tried several alterantives, but gradle is very persistent in telling me that sourceSets does not exist. I also tried workarounds like:

project(':my.sibling.project').the<org.gradle.api.tasks.SourceSetContainer>()["test"].output

… but that gives the error that no such extension exists on the sibling project (all of the sub-projects use Java/Kotlin).

Any idea? Am I missing something? I’ve read about test fixtures, but I would like to keep the general project structure the same in this upgrade.

What you miss is, that you should never ever ever even have tried to do something like that, also not in the older version / other DSL.

That is very problematic and unsafe.

If you want to share things from one project to another, you must use at least an own consumable configuration to share it that you then consume in the other project, or a full feature variant.
Find more information about the tow approaches at Sharing outputs between projects and related samples.

Actually what you are after might be the java-test-fixtures plugin which sets this up for you already as proper variant with a helper for consuming it: Testing in Java & JVM projects