avoid lint when gradle execute check

南笙酒味 提交于 2019-12-08 22:52:57

问题


could someone tell me a way to avoid executing "lint" each time I run in gradle check?

I've defined in build.gradle

lintOptions { 

    quiet true 

}

However, it keeps doing this task. The problem is that it takes ages each time I have to do a check.


回答1:


gradle build -x lint 

Source: Gradle User Guide : Excluding Tasks




回答2:


You can skip it using adding -x lint when you run the check task:

./gradlew check -x lint 

If you want to skip it permanently you can add this to your build.gradle before apply plugin: 'com.android.application':

tasks.whenTaskAdded { task ->
    if (task.name.equals("lint")) {
        task.enabled = false
    }
}



回答3:


I just disabled the task during project setup:

android {
    lintOptions {
        tasks.lint.enabled = false
    }
}

Note: it's not necessary to put the statement inside android.lintOptions, but since it's configuring lint, it's nice to have them together.




回答4:


Set checkReleaseBuilds to false will disable lint check on release build. Add following scripts to your build.gradle file:

lintOptions {
     /**
     * Set whether lint should check for fatal errors during release builds. Default is true.
     * If issues with severity "fatal" are found, the release build is aborted.
     */
    checkReleaseBuilds false
}



回答5:


(Gradle 1.1.0, as packaged with Android Studio 1.1.0)

For anyone wondering how to do this with multiple subprojects, I ended up having to disable them using the root project build.gradle file like so:

task lintCheck() {
    getAllTasks(true).each {
        def lintTasks = it.value.findAll { it.name.contains("lint") }
        lintTasks.each {
            it.enabled = false
        }
    }
}



回答6:


use this code to disable all lint tasks using Gradle's new configuration avoidance API:

tasks.withType(com.android.build.gradle.tasks.LintBaseTask).configureEach {
    enabled = false
}

(tested on Android Gradle plugin 3.3.2.)




回答7:


If you happen to have different build variants, perhaps a more robust script solution would be

afterEvaluate {
  Set<Task> result = tasks.findAll { task -> task.name.startsWith('lintVital') }
  result.each { Task task ->
    task.enabled = false
  }
}



回答8:


If you still want the lint task to work you can also:

project.tasks.check.dependsOn.remove("lint")


来源:https://stackoverflow.com/questions/21143556/avoid-lint-when-gradle-execute-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!