How to set custom Java compiler args on an Android project?

那年仲夏 提交于 2020-12-27 06:12:30

问题


I'm putting the following at the end of my project gradle file:

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs += 
            ['-Xep:MissingOverride:ERROR', 
             '-Xep:MissingCasesInEnumSwitch:ERROR',]
    }
}

However, in my code if I remove an @Override annotation somewhere or remove a switch statement, my Android project still builds. Shouldn't it fail with an error?


回答1:


I googled your problem and found this post that described your problem and the solution looks like this:

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

As is seems the gradle build is different for android projects than for java projects and you can't access the task CompileJava itself as stated in my first comment.



来源:https://stackoverflow.com/questions/42275845/how-to-set-custom-java-compiler-args-on-an-android-project

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