Intellij - Unable to use newer Java 8 classes - Error : "Usage of API documented as @since 1.6+.."

Intellij IdeaJava 8

Intellij Idea Problem Overview


I'm trying to use a java.lang.function.Function in my java 8 code base, but i keep getting the following error in Intellij.

> Usage of API documented as @since 1.6+ This inspection finds all > usages of methods that have @since tag in their documentation. This > may be useful when development is performed under newer SDK version as > the target platform for production

I seem to have the correct Project and Compiler settings

Project Settings: (File -> Project Structure)

Project Settings -> Project -> Project SDK = Java 1.8
Project Settings -> Project -> Project Language Level = 8 - Lambdas, Type Annotations etc

Compiler Settings: (File -> Settings)

Build, Execution, Deployment -> Compiler -> Java Compiler -> Project Bytecode Version : 1.8
Build, Execution, Deployment -> Compiler -> Java Compiler -> Per module Bytecode Version -> Target Bytecode Version : 1.8

What is the problem?

Intellij Idea Solutions


Solution 1 - Intellij Idea

Edited the answer based on Bastien Jansen comment.

Seems that there is another project setting that affects the compiler level. A subtle indication of this problem is when your compiler starts complaining of the source and target java version being different from the one you specified while you are compiling the code

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.

To get rid of this, you need to open up

File -> Project Structure -> Project Settings -> Modules -> "Your Module Name" -> Sources -> Language Level

and change that to the desired level i.e 1.8 or the Project Default language level

Solution 2 - Intellij Idea

If you are using maven then Add below line in your configuration pom.xml file and then reimport or build it from maven.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Else select java compiler and Language Level from below path.

File > Project Structure > Project Settings > Modules > your Module name > Sources > Language Level > choose the one which you need.

enter image description here

Change Language level from here :-

enter image description here

Solution 3 - Intellij Idea

Actually, if you are using Maven and your pom.xml project properties are configured correctly

<project xmlns="...> 
....
<properties>
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
</properties>
...
</project

You can reimport Maven parameters to intellij-idea project - right click on project root entry, then Maven -> Reimport which is at the bottom.

picture shows that Maven is second from last item in project right click menu

Solution 4 - Intellij Idea

I just fixed it as follows:

Right click the project -> Open Module Settings -> Modules -> Sources -> 8 or higher

enter image description here

And then

enter image description here

If still encounter the error and using maven, you have to add the build configuration in your 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>

Solution 5 - Intellij Idea

File > Settings > Build, Execution, Deployment > Java Compiler

Change Target bytecode version to 1.8 of the module that you are working for.

If you are using Maven

Add the compiler plugin to pom.xml under the top-level project node:

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

If you are using Gradle, don't forget to make sure the following is set to 1.8 and not 1.5 (for instance for some bizarre reason in Intelij it defaults to 1.5) so no matter what you do at the project level to set the compiler compatibility level, this setting will cause it to continue giving you trouble with Java 8 features that it would not recognize:

version '1.0-SNAPSHOT'

apply plugin: 'groovy'
apply plugin: 'java'

sourceCompatibility = 1.8

Solution 7 - Intellij Idea

Maybe your config of repository has properties include compiler Version. examine settings.xml file.

<jdk>1.8</jdk>
</activation>
<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>

Solution 8 - Intellij Idea

There is one other place that might be causing this issue, regardless of whether or not you are using Maven or Gradle.

In Settings | Editor | Inspections | Java language level migration aids | Usages of API which isn't available at the configured language level, the default (I believe) is set to Respecting to project language level settings, but it can be set to Higher than: , which ignores project settings.

Meaning that if you follow the instructions in the other answers and set your project's language level to, say, 8, but the inspection is set to Higher than: 7, IDEA will still throw a fit.

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
QuestionAbbas GadhiaView Question on Stackoverflow
Solution 1 - Intellij IdeaAbbas GadhiaView Answer on Stackoverflow
Solution 2 - Intellij IdeaAjay KumarView Answer on Stackoverflow
Solution 3 - Intellij IdeaBoris TreukhovView Answer on Stackoverflow
Solution 4 - Intellij IdeaHearenView Answer on Stackoverflow
Solution 5 - Intellij Ideaharun ugurView Answer on Stackoverflow
Solution 6 - Intellij IdeaBeezerView Answer on Stackoverflow
Solution 7 - Intellij IdeaZesen LiuView Answer on Stackoverflow
Solution 8 - Intellij IdeaCody SView Answer on Stackoverflow