如何在gradle中启用弃用方法警告

时间:2016-03-05 16:45:27

标签: android intellij-idea gradle

当我使用gradle构建项目时,我无法看到有关弃用方法的任何警告,只显示错误。

如何设置build.gradle以显示所有弃用警告(不阻止构建完成)?

2 个答案:

答案 0 :(得分:4)

tasks.withType(JavaCompile) {
    options.compilerArgs << "-Xlint:deprecation"
}

你可以放入你的顶级build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }

    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:deprecation"
    }
}

或在您的模块中:

apply plugin: 'com.android.application'

android {
    ...
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

tasks.withType(JavaCompile) {
    options.compilerArgs << "-Xlint:deprecation"
}

答案 1 :(得分:1)

将此行添加到gradle.properties

org.gradle.warning.mode=all

来源:https://docs.gradle.org/6.1/userguide/build_environment.html#sec:gradle_configuration_properties