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

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

我在使用 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?

在块外指定它是行不通的(因为首先评估 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'
  }
}