In some book I remember reading that we can use the project(Map) dependency factory method to add a dependency on a particular configuration of a module. Today I tried to refactor our builds to add an extra sourceset about test-utils. It looks as follows:
if (file('src/tools').directory) {
logger.info "- 'tools' source set"
sourceSets {
create('tools')
tools {
java.srcDir file('src/tools/java')
groovy.srcDir file('src/tools/groovy')
resources.srcDir file('src/tools/resources')
}
}
configurations {
toolsRuntime.extendsFrom runtime
toolsCompile.extendsFrom compile
testCompile.extendsFrom toolsRuntime
}
dependencies {
toolsCompile sourceSets.main.output
}
}
The idea is that test-utils are not part of the tests, but are separate artifact produced by the module, that assists in testing and can be consumed as a test dependency by other modules. It is just to facilitate the build, i.e. we do not need to be publish it and consume it from outside the current build.
I know I can achieve my use case by adding an extra publication, but I would rather avoid that if possible.