Can I depend on the a particular configuration of a project without publishing to a repository?

(Dimitar Dimitrov) #1

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) { "- 'tools' source set"
    sourceSets {
        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.

(Peter Niederwieser) #2

You need something like:

configurations {
  artifacts {
    tools yourJarTaskForTools

And in dependent projects:

dependencies {

testCompile project(path: “:foo”, configuration: “tools”) }

(Dimitar Dimitrov) #3

Thanks, got it.

Adding for reference of whoever happens to come from internet: the artifacts will not be uploaded to a repository unless they are added to the ‘archives’ configuration.

(Peter Niederwieser) #4

For each configuration, Gradle automatically adds an ‘Upload’ task (e.g. ‘archives’ -> ‘uploadArchives’). The artifacts of a configuration will not be uploaded unless the corresponding ‘Upload’ task is configured and executed.