How to define dependency to another source set than main in composite builds?

Hello.

I’m using the great composite build feature to share some modules across multiple Java projects.

My shared modules define some test fixtures in another source set (each module has main, test and testFixtures source sets).

I would like the modules of my main build (the one that defines the composite build with the shared modules) to depend on the shared modules’ test fixtures in their tests.

To depend on their main source set, I define a dependency using the ${project.group}:${project.name} declaration as explained in the documentation. Gradle automatically substitutes it by the corresponding composite build’s module. This works very well but I don’t know how to do the same thing with the testFixtures source set.

I saw in the documentation that we can manually configure the dependency substitution. My idea was to define the substitution of a virtual artifact (that does not really exists) by a dependency to a project. Something like that (inspired from the documentation):

includeBuild('../share-build') {
    dependencySubstitution {
        substitute module('org.sample:module1-test-fixtures') with project(path: ':shared-build:module1', configuration: 'testFixturesCompile')
    }
}

When I write that in my settings.gradle file, I get the following error:

Could not find method project() for arguments [{path=:shared-build:module1, configuration=testFixturesCompile}] on object of type org.gradle.api.internal.artifacts.ivyservice.dependencysubstitution.DefaultDependencySubstitutions.

Did I do something wrong? Is there a bug? Should I use another approach to solve this issue (if yes, which one)?

Thanks a lot!

After deeper investigation, I noticed that the project method that we use in the dependencySubstitution block belongs to the ProjectDescriptor class and not to the Project one that we use in the dependencies block.

The ProjectDescriptor class does not have a project method accepting a path and a configuration. This explains why I get this error.

I also noticed if I remove the configuration (which I need by the way), the settings.gradle file is still invalid for another reason:

Project :shared-build:module1 not found.

The path I used is wrong. It sounds like the modules coming from composite builds are accessible without prefix. The right project path is :module1.

This makes me think that I will not be able to fix this issue using the dependencySubstitution block, unless we can choose the configuration we need in a future release.

Any ideas about alternative ways to depend on a specific source set?

Thanks in advance.

Did you ever figure this out? I have fought with this exact issue for a few hours now to no avail.