Roger Glover
Roger Glover

Reputation: 3266

Why is my gradle build not loading the most recent dependency?

In most of our gradle projects we have the following dependency:

compile('com.xxx.yyy.zzz:ch-commons:+')

According to our understanding of the documentation, this is supposed to retrieve the most recent version of ch-commons from our maven repository.

tl;dr

Our actual "most recent version" is 1.7.0-SNAPSHOT, but gradle is actually retrieving 1.6.0-SNAPSHOT.

The whole story

Our repository configuration is as follows:

repositories {
    maven { url 'https://local-repo/artifactory/apps-release-local' }  // company application release builds
    maven { url 'https://local-repo/artifactory/apps-snapshot-local' } // company application snapshot builds
    maven { url 'https://local-repo/artifactory/repo1' }               // company lazy mirror of central repos
    mavenCentral()
    jcenter()
}

I have verified that there are no ch-commons artifacts in any of these locations except apps-release-local. And in apps-release-local we have the following contents (sha1, md5, and metadata files elided):

Index of apps-snapshot-local/com/xxx/yyy/zzz/ch-commons

Name                          Last modified      Size
../
1.0.1-SNAPSHOT/               07-Apr-2016 16:09    -
1.0.2-SNAPSHOT/               08-Apr-2016 11:03    -
1.0.3-SNAPSHOT/               08-Apr-2016 14:32    -
1.0.4-SNAPSHOT/               13-Apr-2016 12:33    -
1.1.0-SNAPSHOT/               15-Apr-2016 12:37    -
1.2.0-SNAPSHOT/               17-May-2016 13:16    -
1.2.1-SNAPSHOT/               18-May-2016 14:28    -
1.3.0-SNAPSHOT/               14-Jun-2016 15:42    -
1.4.0-SNAPSHOT/               17-Jun-2016 11:57    -
1.5.0-SNAPSHOT/               17-Jun-2016 13:42    -
1.5.1-SNAPSHOT/               21-Jun-2016 16:16    -
1.6.0-SNAPSHOT/               22-Jun-2016 09:27    -
1.6.2-SNAPSHOT/               30-Jun-2016 22:02    -
1.6.3-SNAPSHOT/               01-Jul-2016 10:42    -
1.7.0-SNAPSHOT/               01-Jul-2016 13:34    -

Looking inside the 1.7.0-SNAPSHOT directory we have the following contents (same stuff elided):

Index of apps-snapshot-local/com/xxx/yyy/zzz/ch-commons/1.7.0-SNAPSHOT

Name                                                  Last modified      Size
../
ch-commons-1.7.0-20160701.183333-1-sources.jar        01-Jul-2016 13:34  14.54 KB
ch-commons-1.7.0-20160701.183333-1.jar                01-Jul-2016 13:34  22.19 KB
ch-commons-1.7.0-20160701.183333-1.pom                01-Jul-2016 13:34  2.21 KB

The contents of apps-snapshot-local/com/xxx/yyy/zzz/ch-commons/maven-metadata-2.xml are as follows:

<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>com.xxx.yyy.zzz</groupId>
  <artifactId>ch-commons</artifactId>
  <version>1.6.3-20160701.154200-1</version>
  <versioning>
    <latest>1.7.0-SNAPSHOT</latest>
    <versions>
      <version>1.0.1-SNAPSHOT</version>
      <version>1.0.2-SNAPSHOT</version>
      <version>1.0.3-SNAPSHOT</version>
      <version>1.0.4-SNAPSHOT</version>
      <version>1.1.0-SNAPSHOT</version>
      <version>1.2.0-SNAPSHOT</version>
      <version>1.2.1-SNAPSHOT</version>
      <version>1.3.0-SNAPSHOT</version>
      <version>1.4.0-SNAPSHOT</version>
      <version>1.5.0-SNAPSHOT</version>
      <version>1.5.1-SNAPSHOT</version>
      <version>1.6.0-SNAPSHOT</version>
      <version>1.6.2-SNAPSHOT</version>
      <version>1.6.3-SNAPSHOT</version>
      <version>1.7.0-SNAPSHOT</version>
    </versions>
    <lastUpdated>20160701183429</lastUpdated>
  </versioning>
</metadata>

Furthermore, if we change the dependency declaration to reference the explicit version:

compile('com.xxx.yyy.zzz:ch-commons:1.7.0-SNAPSHOT')

it then works "correctly", retrieving the correct version 1.7.0-SNAPSHOT.


So, why then isn't the dependency setting with the + version wildcard retrieving the most recent version?

Upvotes: 3

Views: 3060

Answers (2)

Kevin Matthews
Kevin Matthews

Reputation: 69

You can also set changing to true so it doesn't cache snapshots

implementation group: 'com.xxx.yyy.zzz', name: 'ch-commons', version: '1.7.0-SNAPSHOT', changing: true

Upvotes: 2

Akom
Akom

Reputation: 1641

By default, gradle caches SNAPSHOT dependencies for 24 hours.
You can refresh them manually with

--refresh-dependencies

Or you can configure the cache durations as per the guide: https://docs.gradle.org/current/userguide/dependency_management.html#sub:cache_refresh

Upvotes: 11

Related Questions