2

I was working with an aar released on a local maven repository. Since I wanted to include the transitive dependencies, I added the transitiveattribute to my dependencies:

compile ('com.mycompany.domain:artifact:1.0.0@aar') {
    transitive = true
}

Now, let's say that this project add a dependency on the cardView support library v23:

compile "com.android.support:cardview-v7:23.4.0"

What does it happens to my apk release file if I also add a dependency on the v24 cardView library:

compile "com.android.support:cardview-v7:24.0.0"

Does Gradle is able to manage this double dependecy and take the latest one without generating conflict? Or is it safer to specify depedencies manually without using the transitiveattribute.

Also, does the transitive attribute also import the proGuard rules that the aar could have set?

Thank you for your help,

gbaccetta
  • 4,449
  • 2
  • 20
  • 30

2 Answers2

3

Just to add a few details.

You are using the @aar notation.
It means that you want to download only the aar artifact, and no dependencies.
You can check this part of [documentation][1]:
Check the 1.4.1.2. Artifact only notation section:

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, otherwise you can omit the @aar and it will work without adding the transitive attribute.

About the dependencies.
Gradle will manage the dependencies automatically.
With the default configuration gradle will download the newest version.

In any case you can also exclude a dependency in your build.gradle.

 compile('mylibrary:1.0.0') {
     //excluding a particular transitive dependency:
     exclude module: 'xxx' //by artifact name
     exclude group: 'xxx.xxx' //by group
     exclude group: 'xxx.xxxx', module: 'xxxx' //by both name and group

     //disabling all transitive dependencies of this dependency
     transitive = false
 }
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
0

I found myself the answer on the Gradle Official Documentation:Gradle Depedency Management link

Gradle Dependency solver does it automatically. The two main conflict resolution strategies that Gradle offers are:

Newest: The newest version of the dependency is used. This is Gradle's default strategy, and is often an appropriate choice as long as versions are backwards-compatible.

Fail: A version conflict results in a build failure. This strategy requires all version conflicts to be resolved explicitly in the build script. See ResolutionStrategy for details on how to explicitly choose a particular version.

Also, cocerning ProGuard, rules should be exported, if declared in the library with following declaration (see this answer for more details):

defaultConfig {
    consumerProguardFiles 'proguard-rules.txt'
}
Community
  • 1
  • 1
gbaccetta
  • 4,449
  • 2
  • 20
  • 30