【问题标题】:How to Enable deprecate methods warning in gradle如何在 gradle 中启用弃用方法警告
【发布时间】:2016-03-05 16:45:27
【问题描述】:

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

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

【问题讨论】:

    标签: android intellij-idea gradle


    【解决方案1】:
    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"
    }
    

    【讨论】:

    • 这不起作用。 (似乎只与 java xlint 警告有关)
    • 当我运行 gradle 任务gradle app:build 时,我可以清楚地看到:警告:[deprecation] ***() in *** has been deprecated
    • 能否发布您使用的完整 build.gradle 文件?
    • 你只能在编译时看到警告,一定要清理你的项目(Build -> Clean Project)。要查看 Gradle 输出,您需要打开“Gradle 控制台”窗口(右下选项卡)
    • 我仍然看不到有关已弃用的 android 类和方法的任何警告。 Gradle 控制台有大量日志,但我没有看到任何关于已弃用的信息。我必须打开某些特定部分吗?
    【解决方案2】:

    将此行添加到gradle.properties:

    org.gradle.warning.mode=all
    

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

    【讨论】:

      猜你喜欢
      • 2014-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-07
      • 2017-08-02
      • 2018-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多