Java 8 Warning:java: target source value 1.5 is obsolete

Recently creating new Java project in Intellij IDEA 18 I got an error:

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

after several minutes looking in the web I got several possible solutions.

In this post:

  • Solution POM.xml version
  • Solution for Maven project
  • Solution Update Intellij settings
  • Solution Update Eclipse settings
  • Solution Update project file
  • notes about error Warning:java: target source value 1.5 is obsolete

Solution POM.xml version

You can add tags source and target into properties

<?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>

This should be enough to fix the error.

If the previous solution is not working you can change your java version by one of the following solutions:

  • change in maven project pom.xml file - the easiest for maven project
  • update IntelliJ IDEA / Eclipse settings
  • update project file

The reason is due to Maven - a maven project by default uses Java 1.5 compiler. You need to override it to Java 1.8 in the pom.xml file. By definition maven is combination of plugins, so we need to add the compiler plugin and specify the Java compiler version.

Solution for Maven project

Update the POM.xml file for maven project by adding source and target. Copy and paste the whole build section and them import Changes:

<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>

Solution Update Intellij settings

In order to fix your IntelliJ IDEA project follow this steps:

  • File
  • Settings CTRL+ALT+S
  • Search for java compiler
  • change Target byte version to 1.8 ( or the most recent)

Solution Update Eclipse settings

For eclipse you can follow this steps:

  • Right-click on your project
  • Select Property
  • navigate to sources (from the left pane)
  • change your source/Binary Format to JDK 8 (or later)
  • Open build.xml
  • find and replace - 1.5 with 1.8

Solution Update project file

This will be the result of the previous solution. Open file compiler.xml and add this section in it:

    <bytecodeTargetLevel>
      <module name="JavaTests" target="1.8" />
    </bytecodeTargetLevel>

To become :

<project version="4">
  <component name="CompilerConfiguration">
   ...
    <bytecodeTargetLevel>
      <module name="JavaTests" target="1.8" />
    </bytecodeTargetLevel>
  </component>
</project>

Note 1

If you see only this message:

Warning:java: source value 1.5 is obsolete and will be removed in a future release

then check file your_project_name.iml file:

<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5" inherit-compiler-output="false">

and change the version.

Note 2

Three elements should be checked if you want to be sure that your compiler version is correct:

  • pom.xml - java version
  • File / Project Structure - java version
  • File / Settings - compiler version.

The full error

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.

Related Article