How can I suppress javac warnings about deprecated

2019-01-23 00:50发布

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.

9条回答
萌系小妹纸
2楼-- · 2019-01-23 01:00

Two possible ways:

  1. don't use deprecated API
  2. Use @SuppressWarnings("deprecation")
查看更多
何必那么认真
3楼-- · 2019-01-23 01:00

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.

查看更多
来,给爷笑一个
4楼-- · 2019-01-23 01:10

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

查看更多
forever°为你锁心
5楼-- · 2019-01-23 01:18

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
查看更多
Bombasti
6楼-- · 2019-01-23 01:19

When using gradle you can configure it easily:

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

(tested with Gradle 2 and Java 8)

查看更多
唯我独甜
7楼-- · 2019-01-23 01:20

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.)

查看更多
登录 后发表回答