How can I suppress javac warnings about deprecated api?

前端 未结 9 993
遥遥无期
遥遥无期 2020-12-09 01:40

When I compile, javac outputs:

Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.`
相关标签:
9条回答
  • 2020-12-09 01:45

    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.

    0 讨论(0)
  • 2020-12-09 01:47

    When using gradle you can configure it easily:

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

    (tested with Gradle 2 and Java 8)

    0 讨论(0)
  • 2020-12-09 01:50

    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
    
    0 讨论(0)
  • 2020-12-09 02:00

    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.

    0 讨论(0)
  • 2020-12-09 02:01

    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.

    0 讨论(0)
  • 2020-12-09 02:03

    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

    0 讨论(0)
提交回复
热议问题