6

我遇到了 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'
}

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

4

1 回答 1

11

在块之外指定它不起作用(因为首先评估 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'
  }
}
于 2015-06-11T16:26:45.280 回答