I'm working on a project which includes two Android library projects. When I upload these libraries to my Maven repo (Nexus), the generated pom doesn't include a <type>aar</type>
element in the dependency.
Here's my dependency tree
* App1
\
* lib1
|\
| * lib2
* Other libs
You can see in this diagram that my app
depends on lib1
, which depends on lib2
. Both of the libraries are Android library projects, thus AARs.
Lib1/build.gradle
apply plugin: 'com.android.library'
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided project(':lib2')
compile 'com.squareup.picasso:picasso:2.3.3'
}
Lib2/build.gradle
apply plugin: 'com.android.library'
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.squareup.retrofit:retrofit:1.6.1'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
}
Notice how Lib1
includes Lib2
as a project()
dependency.
Now, when I deploy this using Chris Banes' excellent gradle-mvn-push plugin, everything works as expected. There is only one oddity that I notice in the generated pom.xml.
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>lib2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
...
</dependencies>
Notice that the mavenDeployer plugin left out the <type>aar</type>
element in the dependency when it generated the pom.
In my app project (which is a maven project), I have this dependency listed:
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>lib1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>aar</type>
</dependency>
...
</dependencies>
When trying to build this with Maven, I get the following error.
Could not resolve dependencies for project com.example:app:apk:1.0.0-SNAPSHOT: The following artifacts could not be resolved: com.example:lib2:jar:0.0.1-SNAPSHOT
Notice how it's looking for a jar version of the library. I believe, since the mavenDeployer plugin isn't generated the <type>aar</type>
in the dependencies list of the generated pom, maven is defaulting to looking for a jar.
Does anyone know how to build Android library projects that include transient dependencies with Gradle?