How can I tell gradle to use the newest library, snapshot or no?

By : jwir3

I have a personal maven repo setup with the following structure:

root (accessible via http)
 - maven/
   - com/
     - mycompany/
       - core/
         - core/
           - 1.1.0-SNAPSHOT/
           - 1.1.0/
           - maven-metadata.xml
           - maven-metadata.xml.md5
           - maven-metadata.xml.sha1

Now, inside of the 1.1.0 and 1.1.0-SNAPSHOT directories are the appropriate libraries, in aar form (I'm running on android). Inside of the project for which I want to utilize this library's build.gradle file, I have the following:

repositories {                                                                  
    maven { url '' }

dependencies {
      compile 'com.mycompany.core:core:[email protected]'                       

Now, when I do a ./gradlew --refresh-dependencies, it, of course, downloads the version 1.1.0 (not 1.1.0-SNAPSHOT). If I change the dependency to be compile 'com.mycompany.core:core:[email protected]', then it finds the appropriate SNAPSHOT. This is all fine and dandy, but what I really want is to be able to specify the NEWEST version. So, for example, if I had a version of the library 1.2.0, it should find that, or 1.2.0-SNAPSHOT, it should find that. I've tried compile 'com.mycompany.core:core:[email protected]', but that still only finds the version 1.1.0, not 1.1.0-SNAPSHOT, and, if I have 1.2.0 or 1.2.0-SNAPSHOT, it doesn't find those, either.

I'm wondering what the heck the purpose of the + is if it doesn't find the most recent libraries in the repo. Does it only track off of the first version number? Or somehow off of the date?


As suggested, I tried making my build.gradle reference latest.integration, as in: compile 'com.mycompany.core:core:latest.integration' (I also removed the@aar), but when I run./gradlew --refresh-dependencies`, I see the following:

> Could not resolve all dependencies for configuration
> Could not resolve com.mycompany.core:core:latest.integration.
     Required by:
      > java.lang.NullPointerException (no error message)

I'm wondering if this is due to an older version of gradle. It looks like we're using:

mustafar scottjohnson$ ./gradlew --version

Gradle 1.12

Build time:   2014-04-29 09:24:31 UTC
Build number: none
Revision:     a831fa866d46cbee94e61a09af15f9dd95987421

Groovy:       1.8.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
Ivy:          2.2.0
JVM:          1.6.0_65 (Apple Inc. 20.65-b04-466.1)
OS:           Mac OS X 10.10.1 x86_64

It appears that when I run it with --info, it is still looking for 1.2.0 (rather than 1.2.0-SNAPSHOT:

Resource missing. [HTTP GET:]
Resource missing. [HTTP HEAD:]
By : jwir3


"com.mycompany.core:core:latest.integration" should do the trick. ("com.mycompany.core:core: " will have the same effect in some Gradle versions, but will only match releases (i.e. non-snapshots) in other Gradle versions. A safe way to get the latest release version is latest.release.) @aar shouldn't be necessary (assuming a POM with correct packaging type is published) and will disable transitive dependency resolution, which is typically not what you want.

This video can help you solving your question :)
By: admin