How can I suppress javac warnings about deprecated api?

JavaCompiler WarningsJavac

Java Problem Overview


When I compile, javac outputs:

Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.`

I wish to suppress this warning. Trying -Xlint:none does not seem to help.

Java Solutions


Solution 1 - Java

From what I can tell in the docs, you can't do it on the command-line.

According to the javac documentation, -Xlint:none only disables warnings "not mandated by the Java Language Specification". It appears that warning you of the use of deprecated APIs is managed by the language spec.

Your best option would be to fix the use of deprecated APIs. However, an option would be to add the @SuppressWarnings("deprecation") annotation to the classes or methods that are using the deprecated APIs.

Solution 2 - Java

Two possible ways:

  1. don't use deprecated API
  2. Use @SuppressWarnings("deprecation")

Solution 3 - Java

For others that were Google searching this problem and stumble upon this thread like I did...

Try: -Xlint:-deprecation

It seems to work on JDK 6... not sure about others.

Solution 4 - Java

With Java 6, neither the @Depreated annotation, nor a comiler flag will help you here. The only solution that worked for me was to put a javadoc comment with the @deprecated (small caps) tag on the deprecated method:

/**
  * @deprecated overriding deprecated method
  */
@Override
public javax.xml.bind.Validator createValidator() throws JAXBException {...}

(The example is from a class that derives from JAXBContext.)

(I didn't import the deprecated Validator class to avoid a warning on the import statement.)

Solution 5 - Java

When using gradle you can configure it easily:

tasks.withType(JavaCompile) {
    options.deprecation = false
}

(tested with Gradle 2 and Java 8)

Solution 6 - Java

If it's a core Java API, there is almost certainly a replacement that will do what you want. Run the javac with that extra parameter, and then look at the API for the deprecated method and replace as appropriate.

Solution 7 - Java

use nowarn attribute see below

e.g.

<javac srcdir="src" 
  destdir="build/classes" source="1.6" 
  target="1.6" debug="true" encoding="Cp1252"
  nowarn="on">

by default nowarn attribute is off

Solution 8 - Java

@SuppressWarnings("deprecation") is not working for me, instead I've used

@SuppressWarnings("unchecked")

Solution 9 - Java

If you are compiling in the command line you can filter the messages with grep, just filtering out the messages that has unwanted content, like for example grep -v deprecated. You can use | to send the output to grep,

your compile command | grep -v deprecated

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIttayDView Question on Stackoverflow
Solution 1 - JavaThomas OwensView Answer on Stackoverflow
Solution 2 - JavaJoachim SauerView Answer on Stackoverflow
Solution 3 - JavaJeffView Answer on Stackoverflow
Solution 4 - JavaWolfgangView Answer on Stackoverflow
Solution 5 - JavaArne BurmeisterView Answer on Stackoverflow
Solution 6 - JavaMatt PoushView Answer on Stackoverflow
Solution 7 - Javaastra03View Answer on Stackoverflow
Solution 8 - JavaKaushal28View Answer on Stackoverflow
Solution 9 - JavambdView Answer on Stackoverflow