您无法更改配置 'providedRuntime',因为它已被解析

You can't change configuration 'providedRuntime' because it is already resolved

我正在使用 Gradle 2.0 和 Groovy 2.3.3。 当我 运行 下面的构建时,我得到错误 > You can't change configuration 'providedRuntime' because it is already resolved!

其他 posts and release notes 建议与 += 有关,但是,我没有使用该运算符,所以我有点困惑。

apply plugin: 'war'

repositories {
    mavenCentral()
}

//We don't want transitive dependencies added as we are matching a third-party build
configurations.all {
    transitive = false
}

war  {
    archiveName='gradle.war'

    from(configurations.providedRuntime.files) {
      into "app-jars"
    }
    classpath fileTree('webinf-libs') // adds a file-set to the WEB-INF/lib dir.
}

dependencies {
  providedRuntime group: 'com.thoughtworks.xstream', name: 'xstream', version: '1.4.2'
}

正在将 war 配置更改为:

war  {
    archiveName='gradle.war'

    from(configurations.providedRuntime) {
      into "app-jars"
    }
    classpath fileTree('webinf-libs') // adds a file-set to the WEB-INF/lib dir.
}

将解决问题。

问题的发生是因为 fileswar 配置块中被调用并且 然后 依赖被添加到 providedRuntime.由于调用 files 解析配置(并且 war 块在配置阶段进行评估),以后无法修改。

您也可以更改 dependencieswar 的顺序,它们将是相同的。