2017-07-25 14 views
0

要添加庫作爲dependecy本地和儀表單元測試,我需要兩行代碼添加到build.gradle如何在單行中添加本地測試和測試測試的build.gradle相關性?

testCompile "org.mockito:mockito-core:${mockitoVersion}" 
androidTestCompile "org.mockito:mockito-core:${mockitoVersion}" 

是否有可能做到這一點的單行?

我在尋找類似:

bothTestCompile "org.mockito:mockito-core:${mockitoVersion}" 

回答

2

你可以讓配置從其他配置擴展。下面的代碼創建一個新配置,即testCompileandroidTestCompile擴展自。這樣,新配置的每個依賴關係也將是這些配置的依賴關係。

configurations { 
    // Create new configuration 
    bothTestCompile 
    // Let both configurations extend from 'bothTestCompile' 
    testCompile.extendsFrom(bothTestCompile) 
    androidTestCompile.extendsFrom(bothTestCompile) 
} 

現在你可以使用新的配置在你dependencies關閉,就像你在你的例子一樣。

+0

謝謝!這是我正在尋找的。 – andrei