2015-06-30 78 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