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

1

7

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?

Poverty answered 4/6, 2015 at 10:40 Comment(0)
P
12

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'
  }
}
Poverty answered 11/6, 2015 at 16:26 Comment(4)
Btw, SNAPSHOT versions are treated as "changing" by default (if Maven repo is used). Therefore it is not required to set changing = true explicitly.Inoculate
Pretty sure that was there due to a bug in the version of gradle we were using at the time. Now, it's not needed! :)Poverty
can you explain the difference between cacheDynamicVersionsFor and cacheChangingModulesFor ?Cidevant
For posterity, "changing modules" refers to SNAPSHOT versions and any dependency explicitly marked as changing. An example of a dynamic version would be 2.+ which would resolve to the newest 2.x version available.Absonant

© 2022 - 2024 — McMap. All rights reserved.