Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recompile with -Xlint:deprecation

I don't use Android Studio but I build everything from the command line using build.gradle. I generate a Lint report like this:

./gradlew lint 

This correctly generates a Lint report but it also says this:

Note: MyActivity.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 

This makes me wonder how I can do that? I've tried the following:

./gradlew lint -Xlint:deprecation 

But it doesn't work. It says:

Problem configuring task :app:lint from command line. Unknown command-line option '-X'. 

So how can I pass -Xlint:deprecation to Lint via gradle?

like image 220
Andreas Avatar asked Apr 07 '18 20:04

Andreas


People also ask

What does recompile with Xlint mean?

By "recompile with -Xlint", the compiler means to inform you that you need to recompile your program like this: javac -Xlint abc.java. If you do so, the compiler will tell you which methods are deprecated so you can remove your calls to them.

What is Xlint in Java?

The javac -Xlint options control warnings for all files compiled in a particular run of javac . You may have identified specific locations in source code that generate warnings that you no longer want to see. You can use the @SuppressWarnings annotation to suppress warnings whenever that code is compiled.


1 Answers

To answer my own question, you need to add the following to your project-level build.gradle file:

allprojects {     ...      gradle.projectsEvaluated {         tasks.withType(JavaCompile) {             options.compilerArgs << "-Xlint:deprecation"         }     }    } 
like image 77
Andreas Avatar answered Sep 28 '22 03:09

Andreas