When is it required to add @aar when referencing maven artifacts?

5,071 views
Skip to first unread message

Traun Leyden

unread,
Feb 3, 2014, 10:15:00 PM2/3/14
to adt...@googlegroups.com

I have a library that is split into two maven artifacts:

'com.stubworld.core:CorelibJava:1.0' 
'com.stubworld.core:CorelibAndroid:1.0'

The CorelibJava artifact is built by a build.gradle script that uses the java gradle plugin, and is pure java with no android dependencies.  The maven artifact is a jar and here is the pom file.

The CorelibAndroid artifact is built by a build.gradle script that uses the android-library gradle plugin, and depends on the CorelibJava maven artifact.  The maven artifact is an aar and here is the pom file.

I tried to use these libraries from an Android project which uses the 'android' gradle plugin, and after some tweaking I managed to get it to work with the following dependencies:

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.stubworld.core:CorelibJava:1.0'
    compile 'com.stubworld.core:CorelibAndroid:1.0@aar'
}

However, I wasn't really clear on a few things:

* Why do I specifically need to reference the 'com.stubworld.core:CorelibJava:1.0' artifact?  Shouldn't that be automatically resolved since it's an upstream dependency of the  'com.stubworld.core:CorelibAndroid:1.0@aar' artifact?

* Why is the @aar qualifier needed on the  'com.stubworld.core:CorelibAndroid:1.0@aar' artifact?  I have other projects that depend on .aar maven artifacts, and I never needed to add "@aar".

Basically I expected the dependencies to look like this:

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.stubworld.core:CorelibAndroid:1.0'
}

and just want to make sure I'm doing things right.

Xavier Ducrohet

unread,
Feb 4, 2014, 12:13:48 AM2/4/14
to adt...@googlegroups.com
Are those artifacts in your local maven repo?

You shouldn't need to put @aar if the pom declares the packaging as aar (which is true in your case).

However there is an issue right now with the maven local repo support in Gradle that requires using @aar. Also it doesn't automatically follow transitive dependencies so you'd need to do

   compile 'com.stubworld.core:CorelibAndroid:1.0@aar' {
      transitive = true
   }

This will be fixed in Gradle 1.11 and you won't need to add coreLibJava manually or use @aar.



--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Traun Leyden

unread,
Feb 4, 2014, 11:43:36 AM2/4/14
to adt...@googlegroups.com

Are those artifacts in your local maven repo?

Yep.

Also it doesn't automatically follow transitive dependencies so you'd need to do

   compile 'com.stubworld.core:CorelibAndroid:1.0@aar' {
      transitive = true
   }

 This worked, but I did have to make a minor syntax change first to wrap in parens:

    compile('com.stubworld.core:CorelibAndroid:1.0@aar') {
        transitive = true
    }
 
This will be fixed in Gradle 1.11 and you won't need to add coreLibJava manually or use @aar.

Ok cool.  Do you happen to have a link to an issue so I can track it? 

You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/Ll2JcCfgBsQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+u...@googlegroups.com.

Xavier Ducrohet

unread,
Feb 4, 2014, 1:39:14 PM2/4/14
to adt...@googlegroups.com
The Gradle developer I talked to told me this was the bug: http://issues.gradle.org/browse/GRADLE-2984

Roman Mazur

unread,
Feb 7, 2014, 9:59:48 AM2/7/14
to adt...@googlegroups.com
And what if there are 2 files uploaded to Maven Central: jar and aar?
I see that jar is picked by default. And to use aar package I have to specify packaging for a dependency.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

--
You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/Ll2JcCfgBsQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jake Wharton

unread,
Feb 7, 2014, 2:50:49 PM2/7/14
to adt...@googlegroups.com
An artifact can only have a single packaging which is specified in the pom. Additional artifacts type must be qualified when present.

Jigar Brahmbhatt

unread,
Oct 29, 2014, 4:29:01 PM10/29/14
to adt...@googlegroups.com
Hellow Xavier,

Today I switched from Gradle plugin 0.10.+ on IntelliJ 13 to 0.12.1 on Android Studio 0.8.14.

And I'm getting similar problem with a twist.

We have our local nexus OSS setup. 

So whenever I use a non SNAPSHOT version like --> compile '<groupId>:<artifactId>:3.0.0' , it works.

But exact same thing doesn't work when I try to use --> compile '<groupId>:<artifactId>:3_develop-SNAPSHOT', so I had to use @aar with SNAPSHOT and it worked.

Can you think of anything ? Why would this be happening ?

Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

--
You received this message because you are subscribed to a topic in the Google Groups "adt-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/adt-dev/Ll2JcCfgBsQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to adt-dev+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages