Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle How can i specify the cacheResolutionStrategy for the SNAPSHOT version in my buildscript block?

I am having problems with resolutionStrategy.cacheChangingModulesFor.

My project build.gradle looks similar to this

apply plugin: 'base'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply from: "gradle/mixins/cachestrategy.gradle"
configurations.all {
  resolutionStrategy.cacheDynamicVersionsFor 5, 'minutes'
  resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

buildscript {
  repositories {
    maven {
      url artifactoryUrl
    }
  }
  dependencies {
    classpath (group: 'com.myorg', name: 'aCustomPlugin', version: '1.5.0-SNAPSHOT') {
      changing = true
    }
  }
}

allprojects {
  apply plugin: 'base'
  apply plugin: 'com.myorg.aCustomPlugin'
}

my question is: How can i specify the cacheResolutionStrategy for the SNAPSHOT version in my buildscript block?

like image 955
wrossmck Avatar asked Jun 04 '15 10:06

wrossmck


People also ask

How do I force Gradle to use specific dependency?

If the project requires a specific version of a dependency on a configuration-level then it can be achieved by calling the method ResolutionStrategy. force(java. lang. Object[]).

What is buildScript block in Gradle?

The buildScript block determines which plugins, task classes, and other classes are available for use in the rest of the build script. Without a buildScript block, you can use everything that ships with Gradle out-of-the-box.

How do I change the dependencies in Gradle?

To refresh all dependencies in the dependency cache, use the --refresh-dependencies option on the command line. The --refresh-dependencies option tells Gradle to ignore all cached entries for resolved modules and artifacts.


1 Answers

specifying it outside the block, doesn't work (since the buildscript block is evaluated first, in order to build the scripts... ) so the cache strategy rules defined in the scripts haven't been evaluated yet.

the resolution strategy should be placed in the buildscript block like this

buildscript {
  repositories {
    mavenLocal()
    maven {
      url artifactoryUrl
    }
  }
  dependencies {
    classpath (group: 'com.myorg', name: 'aCustomPlugin', version: '1.5.0-SNAPSHOT') {
      changing = true
    }
  }
  configurations.all {
    resolutionStrategy.cacheDynamicVersionsFor 5, 'minutes'
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
  }
}
like image 196
wrossmck Avatar answered Oct 30 '22 02:10

wrossmck