Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 369
ADev Avatar asked Apr 20 '26 05:04

ADev


1 Answers

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.

like image 60
Nico Avatar answered Apr 21 '26 19:04

Nico



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!