在构建 Java 项目时删除 IntelliJ IDEA 上的警告消息

2022-08-31 13:24:59

我第一次使用IntelliJ IDEA Community Edition,并使用Maven设置TDD环境。下面提供了我尝试测试的代码和遇到的警告消息以及项目结构。

项目结构:

enter image description here

法典:

package miscellaneous;

import org.junit.Test;

import static org.junit.Assert.*;

public class TestHello {

    // Methods to be tested.....
    private int Add1Plus1(int i, int j) {
        return (i + j);
    }

    @Test
    public void testAdd1Plus1() throws Exception {
        assertEquals(2, Add1Plus1(1, 1));
    }
}

配置详细信息:

  • Java 编译器:1.8.0_45
  • 版本: 3.0.5
  • Maven 用户设置文件的路径:/home/sandeep/Desktop/MyDocs/repos/git-repos/public/MavenCodeBase/settings.xml
  • Maven local repository: /home/sandeep/Desktop/MyDocs/repos/maven-repos
  • 绒球.xml: http://pastebin.com/462Uytad

警告消息:

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.

问题:

是什么导致了这些消息,修复这些警告消息的好方法/推荐方法是什么?


答案 1

检查你的pom中的java版本.xml(在这里你可以找到如何做到这一点)。还要检查项目结构中的java版本。最后一件事你可以做 - 检查编译器版本,例如

enter image description here


答案 2

我完成了上述所有操作,但仍然有一个警告实例:

Warning:java: source value 1.5 is obsolete and will be removed in a future release

我进入了我的project_name.iml文件并替换了以下标记:

<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">

跟:

<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">

瞧,没有更多的错误消息。希望这有助于某人。


推荐