How do I create a configuration from a base plugin that supports transitive dependencies?


(Mike Damman) #1

I have multi-project with 3 subprojects. I have them defined as the following:

/build.gradle

allprojects {
    apply plugin: 'base'
    configurations {
        compile
    }
}

/project-a/build.gradle

dependencies {
    compile project(':project-b')
}

/project-b/build.gradle

dependencies {
    compile project(':project-c')
}

When I execute the gradle :project-a:dependencies, it only shows project-b as a dependency. I would expect to see project-b AND project-c under project-b.

compile
\--- project :project-b

But if I switch it from apply base plugin to apply java plugin, it does print out project-c

compile - Dependencies for source set 'main' (deprecated, use 'implementation ' instead).
\--- project :project-b
 \--- project :project-c

How do I have the same behavior with a base plugin?


(Chris Doré) #2

When declaring a dependency of project( ':name' ) you are actually declaring a dependency on the default configuration of project :name.

Two solutions:

  1. Add configurations.default.extendsFrom configurations.compile (this is essentially what the java plugin does, but not with the compile configuration).
  2. Declare a dependency on the compile configuration directly. ie compile project( path: 'project-b', configuration: 'compile' )