How can I suppress javac warnings about obsolete api?

When I compile, javac outputs:

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

I want to suppress this warning. Try -Xlint: Nothing helps.

+44
java compiler-warnings javac
Oct 12 '09 at 13:20
source share
8 answers

From what I can say in the docs, you cannot do this on the command line.

According to javac documentation , -Xlint: no one disables warnings that "do not comply with the Java language specifications." There appears to be a warning that using outdated APIs is driven by the language specification.

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

+30
Oct 12 '09 at 13:27
source share

Two possible ways:

+29
Oct 12 '09 at 13:22
source share

For others who googled this problem and stumbled upon this thread, how I did it ...

Try: -Xlint: -deprecation

It seems to be working on JDK 6 ... not sure about the others.

+20
Jun 03 2018-11-11T00:
source share

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

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

(An example from a class that derives from JAXBContext.)

(I did not import the obsolete Validator class to avoid a warning in the import statement.)

+10
Feb 23 '12 at 8:45
source share

When using gradle, you can easily configure it:

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

(tested with gradle 2 and Java 8)

+4
Dec 22 '15 at 13:27
source share

If this is the main Java API, there will almost certainly be a replacement that will do what you want. Launch javac with this optional parameter, and then look at the API for the deprecated method and replace it accordingly.

+1
Oct 12 '09 at 13:25
source share

@SuppressWarnings("deprecation") does not work for me, instead I used

 @SuppressWarnings("unchecked") 
+1
Apr 29 '17 at 9:38 on
source share

use nowarn attribute below

eg.

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

nowarn attribute is disabled by default

0
Dec 16 '14 at 16:56
source share



All Articles