[英]Removing warning messages on IntelliJ IDEA while building Java project
I am using IntelliJ IDEA Community Edition for the first time and using Maven to set up a TDD environment.我是第一次使用 IntelliJ IDEA 社区版,并使用 Maven 来设置 TDD 环境。 The code that I am trying to test and the warning messages I had encountered along with the project structure are provided below.
下面提供了我尝试测试的代码以及我遇到的警告消息以及项目结构。
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));
}
}
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.
What is causing these messages and what would be a good/recommended way to fix these warning messages?是什么导致了这些消息,以及修复这些警告消息的好/推荐方法是什么?
I did all of the above and still had one instance of the warning:我执行了上述所有操作,但仍然有一个警告实例:
Warning:java: source value 1.5 is obsolete and will be removed in a future release
I went into my project_name.iml file and replaced the following tag:我进入了我的project_name.iml文件并替换了以下标签:
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">
with:和:
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
And voila, no more error message.瞧,没有更多的错误信息。 Hope this helps someone.
希望这可以帮助某人。
If the project with Maven, check pom.xml file for source and target:如果项目带有 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>
And in case of Gradle - check build.gradle for:在 Gradle 的情况下 - 检查build.gradle :
plugins {
id 'java'
}
sourceCompatibility = 1.8
In my case none of the above solution worked.就我而言,上述解决方案均无效。 But changing language level in project structure did.
但是在项目结构中改变语言级别确实如此。
File -> Project Structure -> Project Settings -> Modules -> under "sources" tab change language level to some upper version.文件 -> 项目结构 -> 项目设置 -> 模块 -> 在“源”选项卡下将语言级别更改为某个更高版本。
If you have Maven project, open pom.xml file and add following code inside your project root:如果您有 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>
I had this issue in Gradle project of Java.我在 Java 的 Gradle 项目中遇到了这个问题。
In build.gradle file, there was a warning that the assignment was not used.在 build.gradle 文件中,有一个未使用分配的警告。 I removed the
sourceCompatibility = 1.5
line in build.gradle file and all the warning messages disappeared.我删除了
sourceCompatibility = 1.5
文件中的sourceCompatibility = 1.5
行,所有警告消息都消失了。
The real reason is that, your module target jdk version is not same with the IDE.真正的原因是,您的模块目标 jdk 版本与 IDE 不同。 One move to solve this problem: Preferences->Build,Execution,Deployment->Compiler->Java Compiler->Javac Options: uncheck Use compiler from module target JDK when possible Also, others answer about the pom is correct too.
解决这个问题的一个步骤:Preferences->Build,Execution,Deployment->Compiler->Java Compiler->Javac Options: uncheck Use compiler from module target JDK as possible另外,其他人对 pom 的回答也是正确的。
<?xml version="1.0" encoding="UTF-8"?>
<project>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
OR或者
<project>
...
<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>
</configuration>
</plugin>
</plugins>
</build>
</project>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.