Removing warning messages on IntelliJ IDEA while building Java project

JavaIntellij Idea

Java Problem Overview


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.

Project Structure:

enter image description here

Code:

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));
    }
}

Configuration details:

  • Java compiler: 1.8.0_45
  • Maven Version: 3.0.5
  • Path to Maven user-settings file: /home/sandeep/Desktop/MyDocs/repos/git-repos/public/MavenCodeBase/settings.xml
  • Path to Maven local repository: /home/sandeep/Desktop/MyDocs/repos/maven-repos
  • pom.xml: http://pastebin.com/462Uytad

Warning messages:

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.

Question:

What is causing these messages and what would be a good/recommended way to fix these warning messages?

Java Solutions


Solution 1 - Java

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 e.g.

enter image description here

Solution 2 - Java

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.

Solution 3 - Java

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

Solution 4 - Java

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.

enter image description here

Solution 5 - Java

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>

Solution 6 - Java

I had this issue in Gradle project of Java.

In build.gradle file, there was a warning that the assignment was not used. I removed the sourceCompatibility = 1.5 line in build.gradle file and all the warning messages disappeared.

value 1.5 is obsolete and will be removed in a future release

Solution 7 - Java

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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSandeep ChatterjeeView Question on Stackoverflow
Solution 1 - JavaVladyslav SherudaView Answer on Stackoverflow
Solution 2 - JavaBrodView Answer on Stackoverflow
Solution 3 - JavaEduard StreltsovView Answer on Stackoverflow
Solution 4 - JavaHenuView Answer on Stackoverflow
Solution 5 - JavaSuban DhyakoView Answer on Stackoverflow
Solution 6 - JavaYogesh Umesh VaityView Answer on Stackoverflow
Solution 7 - JavaTom KruiseView Answer on Stackoverflow