Groovy 排除Gradle中运行时的某些编译依赖项

Groovy 排除Gradle中运行时的某些编译依赖项,groovy,gradle,Groovy,Gradle,我正在使用Gradle构建Groovy应用程序。像往常一样,我在build.gradle脚本中指定compile依赖项,如下所示: dependencies { // groovy compile "org.codehaus.groovy:groovy:$groovyVersion" compile "org.codehaus.groovy:groovy-json:$groovyVersion" compile "org.codehaus.groovy:groov

我正在使用Gradle构建Groovy应用程序。像往常一样,我在
build.gradle
脚本中指定
compile
依赖项,如下所示:

dependencies {
    // groovy
    compile "org.codehaus.groovy:groovy:$groovyVersion"
    compile "org.codehaus.groovy:groovy-json:$groovyVersion"
    compile "org.codehaus.groovy:groovy-test:$groovyVersion"

    // some more external dependencies...
}
好的,对于运行时,我不需要所有这些依赖项,例如,我不需要任何测试类。因此,我现在要寻找的是一种方法,告诉Gradle,它应该使用与
运行时
编译
相同的依赖项(这是默认的),但不包括其中一些依赖项


有没有一个简单的方法来实现这一点,或者我也必须列出
运行时
的所有依赖项?

相反:Groovy的可传递依赖项通常不需要用于编译(除了由于Groovy编译器的已知限制,它们有时是),但它们在运行时是绝对需要的。但是,在这里优化编译依赖项是不值得的,所以只需将Groovy依赖项声明为
compile
依赖项(这会自动使它们也成为
runtime
依赖项)。Groovy测试依赖项应该添加到
testCompile
配置中。

如果您有只与测试相关的依赖项,那么这就是
testCompile
配置的目的。@OliverCharlesworth:是,但也有其他一些依赖项。例如,Groovy引入了
asm
作为编译的可传递依赖项,但我假设在运行时不需要它……出于好奇,Groovy编译器的限制是什么?它使用标准Java反射来了解编译类路径上的类,如果这些类引用的类不在编译类路径上,这有时会失败。那么这是否意味着运行时需要
asm
,而不是编译<代码>asm
是运行编译器和Groovy代码所必需的(在某些情况下,可能是所有情况下)。编译Groovy代码时,在编译类路径上不需要它(可能是由于我提到的Groovy编译器的限制)。除非你有一个非常具体的理由来尝试和优化这里,否则不要。