74

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?

Sandeep Chatterjee
  • 3,220
  • 9
  • 31
  • 47
  • 2
    Your pom does not show any configuration of the compiler plugin, try setting -[source and -target](http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html) in your pom.xml – A4L Jun 07 '15 at 08:58

7 Answers7

95

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

Community
  • 1
  • 1
Vladyslav Sheruda
  • 1,856
  • 18
  • 26
  • 6
    Ok. So, if I have understood correctly, there is a difference between `File -> Project Structure --> Project(Setting Project SDK to above 1.5)` and `File -> Settings -> Build, Execution, Deployment, Compiler -> Java Compiler` and setting Target bytecode version to above 1.5. – Sandeep Chatterjee Jun 07 '15 at 09:30
  • Yes, the java sdk in all listed above setting must be the same! – Vladyslav Sheruda Jun 07 '15 at 11:15
  • 6
    The fact that they have to be always the same, but aren't located in the same place, is one of my least favorite features of IntelliJ. – Richard Rast Mar 11 '17 at 20:47
  • Is there a configuration setting somewhere, which would always make this get set to a sensible value (i.e. according to selected JDK) when creating a new IntelliJ IDEA project? – Steve Pitchers Apr 03 '17 at 10:43
72

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.

Brod
  • 1,377
  • 12
  • 14
  • 1
    thank you. Was having the same problem. This solved it! – Kai Jan 13 '17 at 15:02
  • 1
    Worked for me too. Need to make the change in the [Answer by Schermann](https://stackoverflow.com/a/30691731/642706) plus this Answer here too. – Basil Bourque Sep 15 '17 at 06:25
  • My .iml file doesn't have that. It instead looks like this: – emirhosseini Dec 04 '18 at 03:41
  • @emirhosseini It depends on how you set up your project. You may not have that tag in your .iml file. If not see suggestions above. :) Good luck – Brod Dec 20 '18 at 21:18
18

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
JCWasmx86
  • 3,473
  • 2
  • 11
  • 29
Eduard Streltsov
  • 1,754
  • 20
  • 19
12

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

Henu
  • 1,622
  • 2
  • 22
  • 27
9

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>
Suban Dhyako
  • 2,436
  • 4
  • 16
  • 38
2

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

Yogesh Umesh Vaity
  • 41,009
  • 21
  • 145
  • 105
2

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>
Tom Kruise
  • 51
  • 2