【问题标题】:Merging different buildType tasks name of Gradle合并 Gradle 的不同 buildType 任务名称
【发布时间】:2018-09-01 22:48:36
【问题描述】:

按照https://stackoverflow.com/a/48494454/3286489,我现在可以在编译我的应用程序之前运行 linting 任务(在 CLI 和 Android Studio 中运行)。

我的代码如下。

android {
//....
    lintOptions {
        abortOnError true
    }
}

tasks.whenTaskAdded { task ->
    if (task.name == 'compileDebugSources' || task.name == 'compileReleaseSources') {
        task.dependsOn lint
        task.mustRunAfter lint
    }
}

不过我不喜欢

task.name == 'compileDebugSources' || task.name == 'compileReleaseSources'

有没有办法将它们结合起来仍然可以正常工作?

【问题讨论】:

  • 我也可以使用task.name.startsWith('compile') && task.name.endsWith('Sources'),但还是不太好。

标签: android gradle build.gradle gradlew


【解决方案1】:

你可以使用正则表达式:

tasks.whenTaskAdded { task ->
    if (task.name.matches('compile(.*)Sources')) {
        task.dependsOn lint
        task.mustRunAfter lint
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-05
    • 1970-01-01
    • 1970-01-01
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    相关资源
    最近更新 更多