Depend only on runtime configuration excluding artifacts

Hi Gradle Community!

project(':core') {
    apply plugin: java
    dependencies {
        runtime 'junit:junit:4.12'
    }
}
project(':a') {
    configurations { 
        myconfig 
    }
    dependencies { 
        myconfig project(path: ':core', configuration: 'runtime') 
    }
    task dump << { 
        println configurations.myconfig.files.join('\n') 
    }
}

gradle dump prints:

core/libs/core.jar
.m2/junit.jar

I want just to depend upon the runtime transitive dependencies of core, and not on core artifacts.

If you don’t need core as a dependency, why do you want to depend on core at all?

Uhmm, good question! I’ll explain why:

I’m migrating a big Maven project with a lot of dependencies between its modules, and jars, wars, and ears. My current problem, actually, is the behavior of EarPlugin. It provides two configurations, deploy and earlib.

  • “deploy” is intended for jar that contains EJBs
  • “earlib” is intended for dependencies of those EJBs (if I understand it correctly).

So my “core” dependency actually produces a Jar with EJBs inside, that depends upon a lot of libraries and other projects.

I was trying, then, to do the following:

dependencies {
    deploy project(':core')
    earlib project(path: ':core', configuration: 'runtime')
}

If I do that, the “earlib” configuration will bring all runtime dependencies and artifacts from “core”.

Instead, if I do something like:

dependencies {
    deploy project(':core')
    earlib project(path: ':core', configuration: 'compile')
}

Then “earlib” will only depend on the “compile” dependencies of “core”, but wont depend on “runtime” only dependencies.

Did you ever solve the problem? I also want to use the runtime configuration for earlib but exclude the artifact already in deploy. I read that it is possible to exclude a module but since I’m adding a project to the deploy config this seems not to be working.