2015-06-30 76 views
0

我可以使用以下代码包含在gradle这个脚本从文件夹罐子排除依赖性罐子在gradle这个使用正则表达式语法

compile fileTree(dir: 'libs', include: '*.jar', exclude: 'antlr-2.7.7.jar') 

我可以使用下面的代码排除多个罐子:

compile fileTree(dir: 'libs', include: '*.jar', exclude: ['antlr-2.7.7.jar', 'antlr-runtime-3.3.jar']) 

但我可以不使用正则表达式的方式,这样排除罐:

compile fileTree(dir: 'libs', include: '*.jar', exclude: 'antlr-.*.jar') 

上面一行不会给任何错误,但它不会排除两个ANTLR罐。是否有可能在gradle中实现这一点。

预先感谢您。

回答

0

您可以使用传递给exclude封闭,例如:

compile fileTree(dir: 'libs', include: '*.jar', exclude: { e -> e.name.startsWith('ant') }) 

当你有,你可以使用正则表达式以及元素的name,而不是startsWith

0

根据documentation,您可以使用略少简化的语法来使用更加明确的文件集,类似于Ant文件集,具有集合差异运算符。

allJars=fileTree(dir: 'libs', include: '*.jar') 
antlrJars=fileTree(dir: 'libs', include: 'antlr-.*.jar') 
jarsToUse=allJars-antlrJars