java: warning: source release 11 requires target release 11

Answered

I've recently updated the Intellij 2020.3.2 (Unlimited Edition),

- I've setup the project structure to 1.8 version.

- I have jdk 1.8

- I've make sure my compiler version is java 8.

But, I am getting "java: warning: source release 11 requires target release 11". Anyone help if I am missing something to configure?

21 comments
Comment actions Permalink

Is it a Maven/Gradle project? Do you have any configuration for the source/target versions in Maven/Gradle build files?

0
Comment actions Permalink

Yes, it is maven project. Even in Spring Boot initial project also got similar issue. 

In addition, i can build project from console. 

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
0
Comment actions Permalink

Did you create project using IDE Spring Initializr wizard? It would be nice if you can describe the exact steps how to reproduce, including the options you have selected in Wizard. Thank you.

>In addition, i can build project from console. 

What JAVA_HOME is set in console?

0
Comment actions Permalink

Hi, 

- I've imported as maven project. File => New => Project from Existing Source and select the Maven project 

- I've Environment Variable setup: 
      JAVA_HOME : C:\Program Files\java\openjdk1.8.0_261
      JRE_HOME: C:\Program Files\java\openjdk1.8.0_261\jre
      M2_HOME: C:\Users\xxxx\apps\apache-maven-3.8.1
     MAVEN_HOME: C:Users\xxxx\apps\apache-maven-3.8.1

 

0
Comment actions Permalink

Thank you. Cannot reproduce this.

Could you please attach screenshots of

File | Project Structure | Modules | <module name> | Sources tab

File | Project Structure | Modules | <module name> | Dependencies tab

Settings (Preferences on macOS) | Build, Execution, Deployment | Compiler | Java Compiler

Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Maven | Importing page?

Please also try version from https://www.jetbrains.com/idea/download/ 

0
Comment actions Permalink

Still not able to successfully build project. Intial issue gone. Now none of the dependency downloaded. Not able to connect to remote repository. I've setup "_JAVA_OPTIONS" environment variable for proxy settings. 

I've enable the override local maven settings files as well. 

0
Comment actions Permalink

Please provide IDE logs (Help | Collect Logs and Diagnostic Data action) after IDE restart and reproducing. 

Do you have antivirus/firewall? Please check for solutions to try: https://intellij-support.jetbrains.com/hc/en-us/articles/360014262940

For uploading you can use https://uploads.jetbrains.com or any file sharing service.

0
Comment actions Permalink

I'm hitting the same issue using Win8.1, IDEA 2021.1.1 and SBT 1.2.8, when trying to use Oracle JDK 1.8.0_121 instead of the one packaged by JetBrains I'm getting:

Executing pre-compile tasks...
Running 'before' tasks
Checking sources
Searching for compilable files...
Reading compilation settings...
scalac: Cannot connect to compile server at localhost/127.0.0.1:3200
Trying to compile without it
Compiling xxx...
scalac: one deprecation (since 2.11.0); re-run with -deprecation for details

Checking dependencies... [xxx]
Dependency analysis found 0 affected files
Updating dependency information... [xxx]
Parsing java... [xxx]
java: warning: source release 11 requires target release 11
Dependency analysis found 0 affected files
Errors occurred while compiling module 'xxx'
javac 11 was used to compile java sources
Finished, saving caches...
Module 'xxx' was fully rebuilt due to project configuration/dependencies changes
Compilation failed: errors: 1; warnings: 0
Synchronizing output directories...
2021-05-10 18:46 - Build completed with 1 error and 2 warnings in 27 sec, 346 ms

Using SBT from command line directly works fine.

Also, I can't refresh SBT project structure - seems that `sbt-structure-extractor_2.12_1.0` is compiled with more recent JDK:

...
[info] Defining Global / sbtStructureOptions, Global / sbtStructureOutputFile and 1 others.
[info] The new values will be used by cleanKeepFiles
[info] Run `last` for details.
[info] Reapplying settings...
[info] Set current project to xxx (in build file:/D:/_Home/eclipse-workspaces/workspace-FS/xxx/)
[info] Applying State transformations org.jetbrains.sbt.CreateTasks from C:/Users/FS/AppData/Roaming/JetBrains/IdeaIC2021.1/plugins/Scala/repo/org/jetbrains/scala/sbt-structure-extractor_2.12_1.0/2021.1.1/sbt-structure-extractor-2021.1.1.jar
[info] Reapplying settings...
[info] Set current project to xxx (in build file:/D:/_Home/eclipse-workspaces/workspace-FS/xxx/)
[error] java.lang.UnsupportedClassVersionError: ch/jodersky/sbt/jni/javah/JavahTask has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
[error] at java.lang.ClassLoader.defineClass1(Native Method)
[error] at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
[error] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[error] at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
[error] at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
[error] at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
[error] at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
[error] at java.security.AccessController.doPrivileged(Native Method)
[error] at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error] at java.lang.Class.getDeclaredMethods0(Native Method)
[error] at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
[error] at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
[error] at java.lang.Class.getMethod0(Class.java:3018)
[error] at java.lang.Class.getMethod(Class.java:1784)
[error] at org.jetbrains.sbt.extractors.UtilityTasks$.reflMethod$Method3(UtilityTasks.scala:145)
[error] at org.jetbrains.sbt.extractors.UtilityTasks$.$anonfun$areNecessaryPluginsLoaded$1(UtilityTasks.scala:145)
...
0
Comment actions Permalink

What JDK is set in Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | sbt | JRE?

Also, what JDK is set for the module(s) in File | Project Structure | Modules | <module name> | Dependencies tab -> Module SDK?

0
Comment actions Permalink

Andrey Dernov Once I change JDK to 1.8 in File | Project Structure | Project SDK, it's also changed for SBT and in module dependencies (both show it as "default" which I didn't override)

0
Comment actions Permalink

Could you please attach screenshots of JDK set in Project Structure for project, modules and sbt? Thank you.

And also the JDK for the Scala compiler server in Settings (Preferences on macOS) | Build, Execution, Deployment | Compiler | Scala Compiler | Scala Compile Server | JDK. Thank you.

0
Comment actions Permalink

I have the same problem and i resolved in Preferences > Java Compiler > Target bytecode version > 8:

 

 

0
Comment actions Permalink

What Language level do you have set in Project Structure | Modules | <module name> | Sources tab? Have you invoked Reload action in sbt tool window?

I cannot reproduce it sorry. If I have JDK 1.8 set for project and same JDK is used for sbt - project builds for me.

Please provide a sample project to check. Thank you.

0
Comment actions Permalink

Language level everywhere is set to 1.8 as well.

Stacktrace makes it pretty obvious that IDEA uses the sbt-jni compiled by the wrong version of Java.

0
Comment actions Permalink

Do you run IDE under 1.8 JDK? Can you provide all IDE logs and full error text? Thanks.

>Using SBT from command line directly works fine.

What JDK is used by sbt from the command line?

0
Comment actions Permalink

I had the same error message - turned out I had a library from a later version of Java included (but not used) in my project structure. Removing that cleared the message.

0
Comment actions Permalink

If your sure you have set what needs to be set, that is the settings under "File | Project Structure"

If your project is maven.

I suggest you "Reload Project" under maven, right click the project name->Maven->Reload Project

It worked for me, i was getting the same error after downgrading to java 8 from 9. Good luck

0
Comment actions Permalink

Hello,

I had a similar issue and I fixed by overriding the following (I is a Maven project but I had to tell IntelliJ to use the proper settings):

In my case it was complaining about JDK 13 and I needed JDK 11.

 

Hope this helps someone,

 

--Jose

0
Comment actions Permalink

I have been experiencing this issue intermittently when importing a new maven project. I've never found the cause, but invalidating the Intellij cache and restarting fixes the issue every time.

0
Comment actions Permalink

Please note that the JDK version that is set for modules in project must not be less than the language level configured for the module in Maven pom.xml. In latest IDE versions we have added a hint that would advise to ament language level or JDK version so that they were compatible.

If the problem still occurs despite that JDK is set correctly please report it to YouTrack with screenshots of the problem. Thank you.

0

Please sign in to leave a comment.