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

San*_*jee 65 java intellij-idea

我是第一次使用IntelliJ IDEA Community Edition并使用Maven来设置TDD环境.我试图测试的代码和我遇到的警告消息以及项目结构如下所示.

项目结构:

在此输入图像描述

码:

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));
    }
}
Run Code Online (Sandbox Code Playgroud)

配置细节:

  • Java编译器: 1.8.0_45
  • Maven版本: 3.0.5
  • Maven用户设置文件的路径: /home/sandeep/Desktop/MyDocs/repos/git-repos/public/MavenCodeBase/settings.xml
  • Maven本地存储库的路径:/home/sandeep/Desktop/MyDocs/repos/maven-repos
  • pom.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.
Run Code Online (Sandbox Code Playgroud)

题:

导致这些消息的原因是什么以及修复这些警告消息的好方法?

Jam*_*ann 80

检查pom.xml中的 java版本(在这里你可以找到它的方法).还要检查项目结构中的 java版本.最后你能做什么 - 检查编译器版本,例如

在此输入图像描述

  • 好.因此,如果我理解正确,那么`文件 - >项目结构 - >项目(将项目SDK设置为1.5以上)和`文件 - >设置 - >构建,执行,部署,编译器 - > Java之间存在差异编译器`并将目标字节码版本设置为1.5以上. (3认同)
  • 它们必须始终相同,但不在同一个地方,这是我最不喜欢的IntelliJ功能之一. (3认同)

Bro*_*rod 65

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

Warning:java: source value 1.5 is obsolete and will be removed in a future release
Run Code Online (Sandbox Code Playgroud)

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

<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">
Run Code Online (Sandbox Code Playgroud)

有:

<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
Run Code Online (Sandbox Code Playgroud)

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


Edu*_*sov 15

如果是使用Maven的项目,请检查pom.xml文件中的源和目标:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.6.1</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <encoding>${project.build.sourceEncoding}</encoding>
      </configuration>
    </plugin>
  </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)


Dar*_*dow 8

就我而言,上述解决方案均无效.但是改变了项目结构中的语言水平.

文件 - >项目结构 - >项目设置 - >模块 - >在"源"选项卡下将语言级别更改为某个高级版本.

在此输入图像描述


Sub*_*ako 7

如果您有Maven项目,请打开pom.xml文件,并在项目根目录内添加以下代码:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>
  </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)