miklesw
miklesw

Reputation: 734

Solution around gradle cache issues with snapshots?

When publishing snapshots to artifactory/mavenLocal, projects won't pick up the latest snapshot. This requires deleting the jar from ~/.gradle/cache

Maven has a feature to set timestamps for snapshots. how would this work with gradle cache?

Upvotes: 3

Views: 1428

Answers (1)

Andrew A. Tasso
Andrew A. Tasso

Reputation: 86

There are two things to consider in resolving your issue:

  1. How Gradle handles/recognizes snapshots
  2. How to override Gradle's default behavior

Some background on how Gradle recognizes/handles snapshots

By default, Gradle will refresh a snapshot dependency every 24 hours.

Gradle will automatically recognize a dependency as a snapshot if the version ends with the -SNAPSHOT suffix. For example:

dependencies {
    compile group: "aGroup", name: "anArtifact", version: "1.0-SNAPSHOT"
}

However, if the dependency's version string does not end with -SNAPSHOT Gradle needs to be told it's a snapshot with the changing parameter. For example:

dependencies {
    compile group: "aGroup", name: "anArtifact", version: "1.0", changing: true
}

Overriding how often Gradle downloads snapshots

The only mechanism for overriding the default 24 hour policy is to configure Gradle to invalidate dependency cache (and thus download a new SNAPSHOT) more frequently. For example:

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

Dynamically versioned dependency cache will need to be configured separately

If you're using any dynamic versions, such as:

dependencies {
    compile group: "aGroup", name: "anArtifact", version: "1.+", changing: true
}

You'll need to configure cache invalidation for those dependencies separately, like this:

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
    resolutionStrategy.cacheDynamicVersionsFor 0, 'seconds'
}

Build performance impact

One thing to note is that the shorter the period of time a dependency is cached the more frequently Gradle will retrieve that artifact. If caching is disabled altogether, it will grab the dependency during each execution.

Upvotes: 3

Related Questions