Gradle如何在我的buildscript块中为SNAPSHOT版本指定cacheResolutionStrategy?

wro*_*mck 4 dependencies gradle dependency-resolution

我遇到了ResolutionStrategy.cacheChangingModulesFor的问题.

我的项目build.gradle看起来与此类似

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'
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:如何在我的buildscript块中为SNAPSHOT版本指定cacheResolutionStrategy?

wro*_*mck 8

在块外部指定它不起作用(因为首先评估buildscript块,以便构建脚本......)因此尚未评估脚本中定义的缓存策略规则.

解决方案策略应该像这样放在buildscript块中

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'
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 顺便说一句,默认情况下,快照版本被视为“更改”(如果使用 Maven 存储库)。因此不需要显式设置 `changed = true`。 (2认同)
  • 您能解释一下cacheDynamicVersionsFor和cacheChangingModulesFor之间的区别吗? (2认同)