How to add -Xlint:unchecked to my Android Gradle based project?

前端 未结 7 906
囚心锁ツ
囚心锁ツ 2020-11-29 16:05

I tried to add the following to the root build.gradle file:

subprojects {
    gradle.projectsEvaluated {
        tasks.withType(Compile) {
              


        
7条回答
  •  情书的邮戳
    2020-11-29 16:30

    Disclaimer: Even though this answer has more than 10 upvotes, it does not address the problem in the context of an Android project. However, Google finds this question in the context of non-Android projects. Thus, I keep this answer for those folks.

    According to JavaCompile, the following seems to be solution:

    compileJava {
        options.encoding = 'UTF-8'
        options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
    }
    

    If you want it to have for the test cases, use compileTestJava

    compileTestJava {
        options.encoding = 'UTF-8'
        options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
    }
    

提交回复
热议问题