Gradle 如何阻止buildSrc自动将groovy all jar作为依赖项应用?

Gradle 如何阻止buildSrc自动将groovy all jar作为依赖项应用?,gradle,groovy,build.gradle,Gradle,Groovy,Build.gradle,我建立了一个Gradle项目,里面有一个buildSrc模块。在buildSrc内部的build.gradle中,我有以下内容: dependencies { compile 'org.codehaus.groovy:groovy-all:2.4.12' ... } 尝试为项目执行生成时,我收到以下错误消息: 2:07:13 PM: Executing external task 'build --stacktrace'... :buildSrc:compileJava NO-

我建立了一个Gradle项目,里面有一个buildSrc模块。在buildSrc内部的build.gradle中,我有以下内容:

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.12'
    ...
}
尝试为项目执行生成时,我收到以下错误消息:

2:07:13 PM: Executing external task 'build --stacktrace'...
:buildSrc:compileJava NO-SOURCE
:buildSrc:compileGroovy FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildSrc:compileGroovy'.
> java.lang.ExceptionInInitializerError (no error message)
在stacktrace中,我看到以下错误:

Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-all is loaded in version 2.4.11 and you are trying to load version 2.4.12
    ... 15 more
因此,当我查看项目结构时,我看到groovy-all-2.4.11.jar自动加载到buildSrc模块中


如果我在build.gradle中删除Groovy的编译依赖项,它会工作,但是有没有办法强制模块使用我想要的Groovy版本

Gradle始终将默认构建脚本应用于buildSrc项目。此脚本包含以下行:

compile localGroovy()
groovy-all-2.4.11就是这样进入的。要覆盖此行为,请尝试设置resolutionStrategy,例如:

但更重要的是,想想看,为什么您要针对groovy版本进行构建,而groovy版本与插件运行时中的版本不同

configurations.compile {
  resolutionStrategy {
    force 'org.codehaus.groovy:groovy-all:2.4.12'
  }
}