Syntax Gradle多编译依赖项语法

Syntax Gradle多编译依赖项语法,syntax,configuration,compilation,gradle,Syntax,Configuration,Compilation,Gradle,我试图在Gradle 1.12中声明一个编译依赖项,其中多个项共享相同的排除子句(这是为了避免到处重复排除)。我知道我可以做这样的事情: configurations { compile.exclude group: 'com.google.gwt' all*.exclude group: 'com.google.guava' } 但这将影响所有配置。我想要的是这样的东西(在Gradle 1.12中不起作用,如下所示): 因此,我可以在一个地方收集所有需要排除的依赖项,并且在其

我试图在Gradle 1.12中声明一个编译依赖项,其中多个项共享相同的排除子句(这是为了避免到处重复排除)。我知道我可以做这样的事情:

configurations {
    compile.exclude group: 'com.google.gwt'
    all*.exclude group: 'com.google.guava'
}
但这将影响所有配置。我想要的是这样的东西(在Gradle 1.12中不起作用,如下所示):

因此,我可以在一个地方收集所有需要排除的依赖项,并且在其他地方仍然可以有:

compile 'com.google.guava:guava:17.0'
更新: 为了澄清,我唯一的目标是替换这段代码:

compile ('bla.bla.bla:1.0'){
  exclude 'same.component:1.0' //Ugly repeat
}
compile ('boo.boo.boo:1.0'){
  exclude 'same.component:1.0' //Ugly repeat
}
compile ('uh.uh.uh:1.0'){
  exclude 'same.component:1.0' //Ugly repeat
}
compile ('oh.oh.oh:1.0'){
  exclude 'same.component:1.0' //Ugly repeat
}
用这种短而甜的东西(目前不起作用):


在仍然能够使用
compile'com.google.guava:guava:17.0'
语法的情况下,没有办法将每个依赖项排除在外
configurations.compile.exclude…
只会影响
compile
配置(以及从其继承的配置),并且几乎总是优于每个依赖项排除

另一种解决方案是使用以下方法排除依赖项声明:

ext.libs = [
    error_data_ioc: dependencies.create("org.jboss.errai:errai-data-ioc:2.4.4.Final") {
        exclude group: 'com.google.gwt' 
        exclude group: 'com.google.guava'
    }
]

然后,您可以在任何需要的地方重用这些声明(例如,
依赖项{compile libs.error\u data\u io}
;也可以从子项目中使用)。如果您真的愿意,您也可以在多个声明之间共享相同的
{exclude…}
块(通过将其分配给一个局部变量)。

谢谢Peter,但我想知道我是否已经很好地解释了我的问题。。。我更新并澄清了这个问题,我简直不敢相信Gradle没有为我想要的东西提供简洁的语法。它很少需要,因此Gradle没有为它提供特殊的语法。当然,您总是可以执行
def excludes={exclude…}
然后
编译“foo:bar:1.0”,excludes
compile( 'bla.bla.bla:1.0'
        ,'boo.boo.boo:1.0'
        ,'uh.uh.uh:1.0'
        ,'oh.oh.oh:1.0'
)
{
    exclude 'same.component:1.0' //Only once! Sweet!
}
ext.libs = [
    error_data_ioc: dependencies.create("org.jboss.errai:errai-data-ioc:2.4.4.Final") {
        exclude group: 'com.google.gwt' 
        exclude group: 'com.google.guava'
    }
]