gradledependenciestransitive-dependencytransitivity

Disable transitive dependencies for everything expect compile project(...)


Is it possible to configure hibernate to only take transitive dependencies from a project I am relying on (compile("foobar")) and disable transitivity for everything else? That's what I tried so far:

configurations.all {
    transitive = false
}
dependencies {
    compile (project(':foobar')) {
        transitive = true
    }
}

It does not work so. No transitive dependencies are pulled at all.

UPDATE 1 as suggested

configurations.all {
    dependencies.matching { it.name != 'foobar' }.all {
        transitive = false
    }
}

Does not take into concern dependencies from foobar though:

compile - Compile classpath for source set 'main'.
+--- project :foobar
+--- junit:junit:3.8.1
+--- org.hibernate:hibernate-c3p0:3.5.6-Final
+--- org.hibernate:hibernate-commons-annotations:3.2.0.Final
+--- org.hibernate:hibernate-ehcache:3.5.6-Final
+--- org.hibernate:hibernate-entitymanager:3.5.6-Final
+--- org.hibernate:hibernate-envers:3.5.6-Final
+--- org.hibernate:hibernate-jmx:3.5.6-Final
+--- postgresql:postgresql:9.1-901.jdbc4
+--- aspectj:aspectjrt:1.5.2
+--- org.apache.tomcat:tomcat-jdbc:7.0.30
\--- org.easymock:easymock:3.2

UPDATE 2

Following solution works for me now:

dependencies {
    compile project(':foobar')

    compile('org.springframework:spring:2.5.6') { transitive = false }
    compile('org.springframework:spring-mock:2.0.3') { transitive = false }
}

Solution

  • Gradle currently does not support to configure the desired behaviour globally. It is possible though by explicitly specifying it for each and every dependency, thus

    dependencies {
       compile project(':foobar')
    
       compile('org.springframework:spring:2.5.6') { transitive = false }
       compile('org.springframework:spring-mock:2.0.3') { transitive = false }
    }
    

    does the trick. Not very nice but working.