【问题标题】:Gradle configuration inheritanceGradle 配置继承
【发布时间】:2017-04-24 23:35:46
【问题描述】:

我在一个 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

【问题讨论】:

  • 你如何定义apple?如果您use initWith(),则可能会复制依赖项,如果在定义构建类型之前定义了依赖项(即,dependencies {} 出现在android {} 之前)。这个我没试过,不知道行不行。
  • @CommonsWare 我正在使用 apple.initwith(debug) 并且我也尝试使用 apple { initWith debug } 它只复制构建变体配置而不是依赖项

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


【解决方案1】:

你可以声明一个新的配置:

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"    
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-12
    • 2021-11-01
    • 2011-02-14
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    相关资源
    最近更新 更多