Gradle multi-project android library support with maven local
I am trying to set up a new project that includes two android library (aar) projects. Name them foo
and bar
.
Since this is all new at the time of writing, I am using Android Studio 1.2.2, Android Build Tools 1.1, Gradle Wrapper 2.2.1.
foo
depends on bar
and for working with Gradle construct I need to specify dependency on sources like this:
dependencies {
compile project(':bar')
}
I need to publish at least foo
to a local maven repository so that it can be picked up by a separate application project baz
that depends on foo
. baz
is in a completely separate project and Gradle build.
I achieved this by using a plugin maven
and adding the following to foo
build.gradle:
task uploadArchives(type: Upload) {
repositories.mavenInstaller {
configuration = configurations.getByName(Dependency.DEFAULT_CONFIGURATION)
pom.groupId = "com.example"
pom.artifactId = "foo"
pom.version = "0.0.2-SNAPSHOT"
}
}
And including maven dependency in line baz
as usual:
dependencies {
compile 'com.example:foo:+'
}
Now the problem I am facing is the application baz
crashes at runtime because it lacks dependencies on bar
! (ClassNotFoundException). Checking foo
aar
which is published to maven local, I can see that it has none of the bar
, and is not specified bar
in pom
for foo
.
How do I get Gradle to include relevant dependency information for foo
in pom
from the information above?
I tried to alternatively change the assembly for foo
specifying bar
as a maven dependency:
dependencies {
compile 'com.example:bar:+'
}
But in this case, the Gradle build for bar
and foo
is failing in the configuration step, because of course, bar
not yet found on maven local (it was not created!) - remember they are both in a multi-project setup.
How does this happen? Are there any pointers to best practices for creating multi-project and android projects projects?
I am also confused about the existence of plugins maven
and maven-publishing
. What is the most appropriate standard for customizing an Android library?
I'm sorry that I included multiple questions in one post. Hopefully when I get some clarity in the right direction that I can edit and make this a more useful question / answer that might help others who are as lost as I am.
Thank!
source to share
Well, after TON has fought and is still not completely sure about the details, I think I have found some light on the matter.
From what I am gathering, defining the bar
source project as a dependency on foo
is the right thing to do. In theory, the maven plugin should be able to create the correct dependencies in the file pom
if everything is configured correctly.
I am having trouble setting up the correct maven post publishing.
What I have been able to do so far is that with help mavenInstaller
everything works easy but is pom
not well formed (dependencies missing). If, on the other hand, I use mavenDeployer
then it pom
is created with dependencies. It took me a lot longer to get it to work because it fails with all exceptions if not configured properly - and I don't know why.
One combination that worked for me and could hopefully help others is this:
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
repository(url: mavenLocal().url)
}
}
}
}
I hope this helps other lost souls and helps bring more clarity on this matter.
source to share