Transitive *false* by default

Hello all,

I’m working with a very large build (several hundred projects).

The transitivity is set to false by default on compile for each sub-project:

configurations {
    compile {
        transitive = false
    }
}

However, specific modules need to revert this transitive default back to true for distinct dependencies. For instance the aws sdk in the following:

dependencies {
    provided group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
    provided group: "com.amazonaws", name: "aws-java-sdk-s3", transitive: true, version: "####"
    provided project(":some:other-project")
}

However this doesn’t work. I think perhaps the general configuration earlier is actually applied after the dependencies are declared, negating the specific transitive setting of the aws sdk.

Is there a way to globally set the transitivity to false while allowing specific cases to re-enable it?

Thanks

I tried to use a resolutionStrategy but it doesn’t give access to the transitivity details of dependencies. Seems all you have access to is the GAV.

It sounds like you’re expecting that setting transitive = false on the configuration is just a convenient way to set the transitive property for each dependency, but these are actually two different concepts.

When the configuration is set to transitive = false, you’re saying nothing in this configuration should resolve transitively. Adding transitive: true on your single dependency isn’t actually doing anything because true is already the default. All of your dependencies (unless they have transitive: false) are actually set to transitive = true, they just don’t resolve transitively because of the transitivity of the configuration. A dependency resolves transitively if it comes from a transitive configuration AND it is transitive itself.

To solve this simply, you probably don’t want to set transitive = false on the compile configuration for the sub-projects that require some transitive resolution. Instead, invert your logic and set transitive = false on the other dependencies.

I don’t think you understood my question.

I don’t want the transitivity of dependencies to be true by default.

Is there a way to set that?

There are thousands of dependencies in this build… I’m not going to each one and setting it transitive = false. I’d rather set the 5-6 which need to be transitive = true.

You could introduce a new configuration for transitive dependencies and have compile extend the new configuration

Eg:

configurations {
   compileTrans 
   compile { 
      transitive = false 
      extendsFrom compileTrans 
   } 
} 

Now you can add transitive deps to compileTrans and non-transitive dependencies to compile

I understood your question, but in order to have a good conversation about possible technical solutions, it was important to understand what the issue was technically (the configuration set to transitive = false will prevent the transitive behavior on any dependency declared in the configuration).

But they are, even in your build, and you don’t really have a choice. True is the default when the dependency object is instantiated, and unless you configure the transitive property of the dependency explicitly, transitive will be true. In your example, “biz.aQute.bndlib” has transitive set to true, even though you didn’t set it.

You’re just setting the configuration transitive property to false, not the default of each dependency.

The suggestion was not to set every single dependency in your several hundred sub-projects to transitive = false. The suggestion was that you look at the sub-projects that contain those 5-6 dependencies, and see if you can make a change just in those few places without too much issue.

I wouldn’t want to add complexity in structure or implementation unless you really needed it.

Ok, got it!

This is what I would like to change… there’s no need for that to be statically defined.

Only because that is hard coded!

I’m asking how I would accomplish that.

This still implies lots of configuration. It means that in each module I have to set the configuration transitive = false, this is already hundreds of duplications. Then in those few modules set every dependency except those few transitive = false instead of the configuration.

I’m going to try @Lance_Java’s proposal in the meantime.

If that proves not to work, I think I will make a PR to gradle to have a property which eliminates the hard coded transitive behaviour of true and merely sets it as the default.

@Lance_Java the idea was good but doesn’t solve my use case:

Given a configuration like:

dependencies {
    compile group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "2.4.1"
    compileTrans group: "com.google.apis", name: "google-api-services-oauth2", transitive: true, version: "v2-rev98-1.21.0"
    compile group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
    compile group: "org.osgi", name: "org.osgi.core", version: "5.0.0"
    compile group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"
    compile project(":blah:foo")
}

The transitive configuration seems to clobber everything at a lower level.

In other words, I still see a dependency tree like this:

compile - Compile classpath for source set 'main'.
+--- biz.aQute.bnd:biz.aQute.bndlib:2.4.1
+--- com.google.apis:google-api-services-oauth2:v2-rev98-1.21.0
+--- javax.servlet:javax.servlet-api:3.0.1
+--- org.osgi:org.osgi.core:5.0.0
+--- org.osgi:org.osgi.service.component.annotations:1.3.0
\--- project :blah:foo

while what I wish to see is (fabricated):

compile - Compile classpath for source set 'main'.
+--- biz.aQute.bnd:biz.aQute.bndlib:2.4.1
\--- com.google.apis:google-api-services-oauth2:v2-rev98-1.21.0
|    \--- com.google.api-client:google-api-client:1.21.0
|         +--- com.google.oauth-client:google-oauth-client:1.21.0
|         |    +--- com.google.http-client:google-http-client:1.21.0
|         |    |    +--- com.google.code.findbugs:jsr305:1.3.9
|         |    |    \--- org.apache.httpcomponents:httpclient:4.0.1
|         |    |         +--- org.apache.httpcomponents:httpcore:4.0.1
|         |    |         +--- commons-logging:commons-logging:1.1.1
|         |    |         \--- commons-codec:commons-codec:1.3
|         |    \--- com.google.code.findbugs:jsr305:1.3.9
|         +--- com.google.http-client:google-http-client-jackson2:1.21.0
|         |    +--- com.google.http-client:google-http-client:1.21.0 (*)
|         |    \--- com.fasterxml.jackson.core:jackson-core:2.1.3
|         \--- com.google.guava:guava-jdk5:17.0
+--- javax.servlet:javax.servlet-api:3.0.1
+--- org.osgi:org.osgi.core:5.0.0
+--- org.osgi:org.osgi.service.component.annotations:1.3.0
\--- project :blah:foo

Attempt 2:

configurations {
   compileTrans 
   compile { 
      transitive = false
      dependsOn compileTrans
   } 
}
dependencies {
    compileTrans group: "com.google.apis", name: "google-api-services-oauth2", version: "v2-rev98-1.21.0"
    compile project(":blah:foo")
    ... 
    compile configurations.compileTrans.files
}

We’re going to try this and various other things. I’ll post status when I get some.

thx all