205

What does Gradle transitive = true do exactly? It is not clear from the Gradle documentation. This is in the context of compile within build.gradle. In my case I'm depending Android's crashlytics.

compile('com.crashlytics.sdk.android:crashlytics:2.2.2@aar') {
    transitive = true;
}

Several Gradle docs (here and here) imply that "transitive" defaults to true. Yet removing transitive = true results in transitive dependencies not being brought in (in particular KitGroup).

class file for io.fabric.sdk.android.KitGroup not found

The docs say it defaults to true, yet the actual behavior seems to be the opposite.

I am running Gradle 2.2.1. Perhaps the behavior changed between 2.2 and 2.4?

Edit: Related Transitive dependencies not resolved for aar library using gradle

Community
  • 1
  • 1
Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
  • when defining configurations, or when defining dependencies? – dnault Jul 30 '15 at 18:24
  • Dependencies of jar files are promoted to sub projects. Not every project need to define it's dependencies explicitly. – Konrad Jul 30 '15 at 18:30
  • What exactly is not clear in [this documentation](https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.Configuration.html#org.gradle.api.artifacts.Configuration:transitive)? – Oleg Estekhin Jul 30 '15 at 18:34
  • 4
    @OlegEstekhin the documentation doesn't match the runtime behavior I'm seeing – Steve Kuo Jul 30 '15 at 20:54

6 Answers6

176

You are using the @aar notation.
It means that you want to download only the aar artifact, and no transitive dependencies.

You can check Dependency management in Gradle in the official documentation. In particular:

An artifact only notation creates a module dependency which downloads only the artifact file with the specified extension. Existing module descriptors are ignored.

Using the @aar notation if you want to download the dependencies, you should add transitive=true.

I'd expect that omitting @aar it should work without adding the transitive attribute.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • 7
    I confirmed that omitting @aar and removing the transitive attribute works. The intention here is that developers reference the Fabric kits explicitly (e.g., "compile 'com.crashlytics.sdk.android:crashlytics:2.5.5'"), and that the core io.fabric.sdk.android classes be pulled in via transitive dependency. If you set transitive=false, then the io.fabric.sdk.android.Fabric class will not be found at compile time. – Mark McClelland Feb 25 '16 at 17:56
  • 8
    this "feature" is so bad, i want an aar with its dependencies. without the @aar it searches for jar and complains – dowi Apr 26 '17 at 13:08
  • What's the point of it, then? Why not avoid using "@aar" and "transitive=true" together? – android developer Apr 07 '21 at 14:39
17

On a more general note: Setting transitive = false on the crashlytics library causes gradle to ignore all libraries required by crashlytics (="transient libraries") and not download and link them.

You would have to either manually add the required libraries to your project or rely on other transient libraries added by other dependencies.

Default for gradle is transitive = true.

Examples and full explanation here: http://www.devsbedevin.net/android-understanding-gradle-dependencies-and-resolving-conflicts/

Vaiden
  • 15,728
  • 7
  • 61
  • 91
  • 1
    link doesn't work. I'm afraid it is not by default true, because in some cases specifically write true – Morozov Jul 31 '19 at 11:39
5

My guess is that the Crashlytics artifact to which you're referring manually specifies dependencies as not transitive (transitive=false) so that you aren't forced to bring those dependencies in by default. That's why you're seeing the opposite behavior. For example some developers may not want to pull in all of Google Play Services or whatever else Crashlytics may use if present.

So, by removing that, Gradle no longer pulls in the dependency, and it fails to build. You can specify that dependency manually if you need to.

That being said - I think the bigger issue at hand is that you shouldn't be referencing the Crashlytics artifact directly - you should be using Fabric, and pulling in Crashlytics as a result: https://dev.twitter.com/fabric/android/integrating

Sam Dozor
  • 40,335
  • 6
  • 42
  • 42
  • The instructions for migrating to Fabric specify referencing the Crashlytics artifact directly, presuming you are using that Fabric "kit": https://fabric.io/migrations/gradle – Mark McClelland Feb 25 '16 at 17:09
  • It looks like the intention is that you reference the kits directly, and they pull in the io.fabric.sdk.android classes via transitive dependency. – Mark McClelland Feb 25 '16 at 17:41
1

Sets whether this dependency should be resolved including or excluding its transitive dependencies. The artifacts belonging to this dependency might themselve have dependencies on other artifacts. The latter are called transitive dependencies.

1

Gradle follows transitive dependencies by default. If you want to turn that off for a particular library, use the transitive flag.

Changing the value of the transitive flag to false prevents the download of transitive dependencies, so you’ll have to add whatever is required yourself. If you only want a module jar, without any additional dependencies, you can specify that as well.

Hongyuan
  • 100
  • 6
-25

transitive controls transitivity. Gradle normally defaults to transitive, except when it doesn't. There's a bug with transitivity and classifiers, see https://issues.gradle.org/browse/GRADLE-3188.

Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
  • 47
    I think it's fair that you pointed out a bug. But, your description of the property isn't helpful. "transitive controls transitivity. Gradle normally defaults to transitive, except when it doesn't." Really, dude?... Really? – w3bshark Apr 27 '16 at 17:49
  • 6
    @w3bshark I thought it was funny. "defaults to transitive, except when it doesn't" is pretty accurate in my experience. – Navin May 10 '16 at 20:37