3

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?

asked Feb 16, 2017 at 13:50
6
  • I don't know if it behaves different for android projects but for our java EE build I implemented this: compileJava{ options.fork = true options.forkOptions.executable = 'javac' options.compilerArgs.addAll( [ '-APackageAcronym='+gradle.ext.packageAcronym, '-s', gradle.ext.generatedQueriesDir ] ) } since compileJava is it's own task. Commented Feb 16, 2017 at 14:10
  • Do you put compileJava at the root level? If I do so in my case I get the following error message: "Error: Could not find method compileJava() ..." Commented Feb 16, 2017 at 14:21
  • 1
    Yes I put it at the root level. I think it's different for android gradle builds? Just thought to give it a shot :) Sorry I wasted you're time. Commented Feb 16, 2017 at 14:45
  • No, thanks for the suggestion! Appreciate you giving the time. :) Commented Feb 16, 2017 at 14:51
  • 1
    I googled a bit and it seems android really hides the task compileJava and denies access to it. But I found this peace which seems to work for other users allprojects { gradle.projectsEvaluated { tasks.withType(JavaCompile) { options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" } } } found here: stackoverflow.com/questions/18689365/… information for compileJava task: stackoverflow.com/questions/16853130/… Commented Feb 17, 2017 at 6:22

1 Answer 1

15

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.

superjos
12.8k6 gold badges95 silver badges143 bronze badges
answered Feb 17, 2017 at 11:42
Sign up to request clarification or add additional context in comments.

1 Comment

Sir, I salute you. This was a pain, and you solved it! I wonder why Android Studio does not have a clear option for that in the project settings. Anyway, thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.