Is there a way to replace a transitive dependency by another?

(Rafael Brandão) #1

My project is targeted to run in an OSGI container.

It has several sub-modules, most of them heavily depend on spring (framework, integration, amqp) libraries.

The problem is that most of those spring dependencies have transitive dependencies on non OSGI compatible libraries, such as aopalliance:1.0 and commons-logging:1.1.1.

So I have to exclude commons-logging and aopaliance libraries from all my configurations and declare a global runtime dependency on “osgified” libraries, such as jcl-over-slf4j and aopaliance provided by spring ebr repository. This would impact sub-projects that do not depend on spring libraries.


allprojects {
    afterEvaluate {
        configurations.all { conf ->
            conf.exclude group: "aopalliance", module: "aopalliance"
            conf.exclude group: "commons-logging", module: "commons-logging"
          dependencies {
            // From Spring EBR repository
            runtime "${aopallianceVersion}"
            // From Maven central repository
            runtime "org.slf4j:jcl-over-slf4j:${slf4jVersion}"

Or I could manually override first level dependencies that results on transitive dependencies like aopaliance or commons-logging, witch would be overkill and could easily become a maintenance nightmare.

In one of my projects I declared a compile dependency on spring-integration-core.


dependencies {
    compile "${springIntegrationGroup}:spring-integration-core:${springIntegrationVersion}"

When I run gradle -q dependencies I get:

Is there a way to get the transitive dependency commons-logging library replaced by jcl-over-slf4j?

Let’s suppose this:

configurations.all { conf ->
    **conf.replace {
        group: "commons-logging"
        module: "commons-logging"
        replacement: "org.slf4j:jcl-over-slf4j:${slf4jVersion}"

Is that possible? That would be really nice.

My gradle -v output:

------------------------------------------------------------ > Gradle 1.3 > ------------------------------------------------------------ > > Gradle build time: Tuesday, November 20, 2012 11:37:38 AM UTC > Groovy: 1.8.6 > Ant: Apache Ant™ version 1.8.4 compiled on May 22 2012 > Ivy: 2.2.0 > JVM: 1.7.0_07 (Oracle Corporation 23.3-b01) > OS: Windows 7 6.1 amd64

(Luke Daley) #2

It’s not possible at the moment, but it’s something we’ll add.

At the moment, you’ll need to do the exclude dance for each project that drags in the jars you don’t want.

Is there an elegant way to replace a transitive dependency by another?