I am using IntelliJ IDEA Community Edition for the first time and using Maven to set up a TDD environment. 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?
Check java version in your pom.xml ( here you can find how to do it). Also check java version in Project Structure . And the last what you can do - check compiler version eg
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:
<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:
<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:
plugins {
id 'java'
}
sourceCompatibility = 1.8
If you have Maven project, open pom.xml file and add following code inside your project root:
<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>
The real reason is that, your module target jdk version is not same with the 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.
<?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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.