Gradle配置继承

时间:2017-04-24 23:35:46

标签: android gradle groovy android-gradle android-build

我在gradle文件中有多个依赖项,我引入了一个新的构建变体调用“apple”。但我不想复制和粘贴如下。

dependencies {
    debugCompile "com.android:libraryA:1.0.0"    
    debugCompile "com.android:libraryB:1.0.0"    
    debugCompile "com.android:libraryC:1.0.0"    

    appleCompile "com.android:libraryA:1.0.0"    
    appleCompile "com.android:libraryB:1.0.0"    
    appleCompile "com.android:libraryC:1.0.0"    
}

我可以说appleCompile取决于debugCompile吗?

1 个答案:

答案 0 :(得分:2)

您可以声明新配置:

configurations {
    [debugCompile, appleCompile].each { it.extendsFrom commonCompile }
}

现在commonCompile配置将为debugapple配置应用依赖项,因此您无需指定两次。

dependencies {
    commonCompile "com.android:libraryA:1.0.0"    
    commonCompile "com.android:libraryB:1.0.0"    
    commonCompile "com.android:libraryC:1.0.0"    
}