Maven 项目报出警告:Warning:java: source value 1.5 is obsolete and will be removed in a future release


文章目录

      • `临时`生效方式。
      • `永久`生效方式。


使用 Maven 项目运行程序时,报出警告

Warning:java: source value 1.5 is obsolete and will be removed in a future release
Warning:java: target value 1.5 is obsolete and will be removed in a future release
Warning:java: To suppress warnings about obsolete options, use -Xlint:-options.

这是因为 Maven 内置 jdk 编译环境是 1.5 版本。
使用 maven 开发项目时,不会使用 IDEA 设置的 jdk,而是使用 Maven 内置的 jdk 编译器。
如需使用较新的版本,需要我们自己指定版本号。


临时生效方式。

参考 Maven 官网。

  • 方式 1。
    中。

设置 Java 编译器的 -source-target

Setting the -source and -target of the Java Compiler
Sometimes when you may need to compile a certain project to a different version than what you are currently using. The javac can accept such command using -source and -target. The Compiler Plugin can also be configured to provide these options during compilation.

For example, if you want to use the Java 8 language features (-source 1.8) and also want the compiled classes to be compatible with JVM 1.8 (-target 1.8), you can either add the two following properties, which are the default property names for the plugin parameters:

只要在 pom 文件的 标签内加入


  [...]
  
    1.8
    1.8
  
  [...]

  • 方式 2。
    中。

只要在项目的 pom 文件中加入
标签内)。




    
    
        
            org.apache.maven.plugins
            maven-compiler-plugin
            3.8.1
            
                1.8
                1.8
            
        
    
    



这样在下一次运行程序时就会用你指定的 jdk 版本,不会报出(jdk 1.5 版本)警告。


以上方式只是临时对当前项目生效,想要一劳永逸永久生效,就需要修改 Maven 的配置文件。

永久生效方式。

编辑 Maven 目录 /apache-maven-3.6.3/conf 下的 settings.xml

中加入



    jdk-1.8

    
        true
        1.8
    

    
        1.8
        1.8
        1.8
    



再次运行项目,就不再报出警告。


以下为原文件注释备份。

  
    

    
  

你可能感兴趣的:(Java,Maven)