264

I'm using IntelliJ IDEA Ultimate 2019.3.1. Whenever I try to start any simple Java Maven project (may it be even a simple Hello World) I get the following error:

Error:java: error: release version 5 not supported

Running java --version by terminal I get the following output:

openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.1)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.1, mixed mode, sharing)

Running javac --version by terminal I get the following output:

javac 11.0.5

Going to the Settings of the Java Compiler ( as suggested here ) I see this:

Java Compiler Settings

I tried editing the "Target bytecode version" to 1.8 but I get the following errors:

Error:(1, 26) java: package javafx.application does not exist
Error:(2, 20) java: package javafx.stage does not exist
Error:(4, 27) java: cannot find symbol
  symbol: class Application
Error:(12, 23) java: cannot find symbol
  symbol:   class Stage
  location: class Main
Error:(7, 9) java: cannot find symbol
  symbol:   method launch(java.lang.String[])
  location: class Main
Error:(11, 5) java: method does not override or implement a method from a supertype

Changing it to version 1.11 I get this error instead:

Error:java: Source option 5 is no longer supported. Use 6 or later.

What do you think is the problem? How may I solve it?

Robb1
  • 4,587
  • 6
  • 31
  • 60
  • 1
    What is the language level of the project and the modules? – Bas Leijdekkers Jan 05 '20 at 17:04
  • 1
    Similar https://www.blogger.com/blogger.g?blogID=1500918374284731344#editor/target=post;postID=6418978702757725686;onPublishedMenu=allposts;onClosedMenu=allposts;postNum=7;src=postname – soorapadman Jan 06 '20 at 08:40

24 Answers24

467

See https://stackoverflow.com/a/12900859/104891.

First of all, set the language level/release versions in pom.xml like that:

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

Maven sets the default to 1.5 otherwise. You will also need to include the maven-compiler-plugin if you haven't already:

<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.1</version>
</dependency>

Also, try to change the Java version in each of these places:

File -> Project structure -> Project -> Project SDK -> 11.

File -> Project structure -> Project -> Project language level -> 11.

File -> Project structure -> Project -> Modules -> -> Sources --> 11

In project -> ctrl + alt + s -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Project bytecode version -> 11

In project -> ctrl + alt + s -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Module -> 1.11.

Konstantin Annikov
  • 11,655
  • 4
  • 27
  • 40
91

Took me a while to aggregate an actual solution, but here's how to get rid of this compile error.

  1. Open IntelliJ preferences.

  2. Search for "compiler" (or something like "compi").

  3. Scroll down to Maven -->java compiler. In the right panel will be a list of modules and their associated java compile version "target bytecode version."

  4. Select a version >1.5. You may need to upgrade your jdk if one is not available.

enter image description here

Pang
  • 9,564
  • 146
  • 81
  • 122
borisveis
  • 911
  • 5
  • 2
27

By default, your "Project bytecode version isn't set in maven project.

It thinks that your current version is 5.

Solution 1:

Just go to "Project Settings>Build, Execution...>compiler>java compiler" and then change your bytecode version to your current java version.

Solution 2:

Adding below build plugin in POM file:

 <properties>
        <java.version>1.8</java.version>
        <maven.compiler.version>3.8.1</maven.compiler.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
Pang
  • 9,564
  • 146
  • 81
  • 122
Arjun Marati
  • 397
  • 3
  • 3
10

I add the following code to my pom.xml file. It solved my problem.

<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>
Pang
  • 9,564
  • 146
  • 81
  • 122
10

In my case it was enough to add this part to the pom.xml file:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
        </plugins>
    </build>
Krzysztof Tomaszewski
  • 1,033
  • 11
  • 16
9

I did everything above but had to do one more thing in IntelliJ:

Project Structure > Modules

I had to change every module's "language level"

tataelm
  • 679
  • 8
  • 17
9

You should do one more change by either below approaches:


1 Through IntelliJ GUI

As mentioned by 'tataelm':

Project Structure > Project Settings > Modules > Language level: > then change to your preferred language level


2 Edit IntelliJ config file directly

Open the <ProjectName>.iml file (it is created automatically in your project folder if you're using IntelliJ) directly by editing the following line,

From: <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">

To: <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">

As your approach is also meaning to edit this file. :)


Approach 1 is actually asking IntelliJ to help edit the .iml file instead of doing by you directly.

garykwwong
  • 2,327
  • 2
  • 16
  • 20
  • 1
    I followed all other steps, set the JDK to 11 in every possible option in the IDE, but somehow .iml still had "JDK_1_5", so your step 2. did it for me, I had to change it manually. Thanks. – Arier Feb 10 '21 at 02:18
6

If your are using IntelliJ, go to setting => compiler and change the version to your current java version.

Pang
  • 9,564
  • 146
  • 81
  • 122
6

The only working solution in my case was adding the following block to pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version> <configuration> <release>12</release>
        </configuration>
        </plugin>
    </plugins>
</build>
Pang
  • 9,564
  • 146
  • 81
  • 122
Muhammed Gül
  • 825
  • 10
  • 19
4

You only have to add these two lines in your pom.xml. After that, your problem will be gone.

<!--pom.xml-->
<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

Pang
  • 9,564
  • 146
  • 81
  • 122
Mehedi Abdullah
  • 772
  • 10
  • 13
4

The solution to the problem is already defined in some of the answers. But there is still a need to express a detail. The problem is totally related to maven, and the solution is also in the pom.xml configuration. IntelliJ only reads maven configuration, and if the configuration has wrong information, IntelliJ also tries to use that.

To solve the problem, as expressed in the most of the answers, just add the below properties to the pom.xml of the project.

<properties> 
      <maven.compiler.source>1.8</maven.compiler.source> 
      <maven.compiler.target>1.8</maven.compiler.target> 
</properties>

After that, on the IntelliJ side, reimport maven configuration. To reimport the maven configuration, right click on pom.xml file of the project and select Reimport. Compiler version related information in IntelliJ preferences will be automatically updated according to the values in the pom.xml.

Pang
  • 9,564
  • 146
  • 81
  • 122
ayhan
  • 129
  • 1
  • 4
3

I had the same issue but with a small difference. My error message was the following.

IntelliJ: Error:java: error: release version 16 not supported

So in Intellij go to

  • File
  • Settings
  • Build, Execution, Deployment
  • Compiler

In here there is field called "Project bytecode version". There the default value was 16, I changed it to 8 and everything worked fine.

3
  1. File->Settings

enter image description here

  1. From left side ->"Build, Execution, Deployment" ->"java compiler"

enter image description here

  1. choose the project that you work on and choose the java version you need

enter image description here

Vladi
  • 1,662
  • 19
  • 30
2

If you are using spring boot as a parent, you should set the java.version property, because this will automatically set the correct versions.

<properties>
   <java.version>11</java.version>
</properties>

The property defined in your own project overrides whatever is set in the parent pom. This overrides all needed properties to compile to the correct version.

Some information can be found here: https://www.baeldung.com/maven-java-version

Pang
  • 9,564
  • 146
  • 81
  • 122
V Jansen
  • 89
  • 3
  • 1
    I'm also starting learning about Spring Boot now, so this information can be really useful for me :) can you please explain it more in detail? (In what file should I change those properties, what should I write exactly...?) Thanks! – Robb1 Jan 06 '20 at 11:06
  • 2
    I added some extra info in my post. – V Jansen Jan 07 '20 at 12:22
2

Found one more place to change, which actually fixed for me.

Project Structure -> < Select Module > Dependencies -> Module SDK < Select version from drop down >

enter image description here

Manish
  • 1,452
  • 15
  • 25
2

1.use this properties

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

2.Add this dependency

 <dependency>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.1</version>
    </dependency>

3.Reload mvn

Biddut
  • 418
  • 1
  • 6
  • 17
1

Within IntelliJ, open pom.xml file.

Add this section before <dependencies> (if your file already has a <properties> section, just add the <maven.compiler...> lines below to that existing section):

<properties> 
   <maven.compiler.source>1.8</maven.compiler.source> 
   <maven.compiler.target>1.8</maven.compiler.target> 
</properties>
Pang
  • 9,564
  • 146
  • 81
  • 122
Ali Shah
  • 31
  • 1
1

I've done most things you are proposing with Java compiler and bytecode and solved the problem in the past. It's been almost 1 month since I ran my Java code (and back then everything was fixed), but now the problem appeared again. Don't know why, pretty annoyed though!

This time the solution was: Right click to project name -> Open module settings F4 -> Language level ...and there you can define the language level your project/pc is.

No maven/pom configuration worked for me both in the past and now and I've already set the Java compiler and bytecode at 12.

Dharman
  • 30,962
  • 25
  • 85
  • 135
1

You need to set language level, release version and add maven compiler plugin to the pom.xml

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.1</version>
</dependency>
User
  • 1,460
  • 14
  • 11
1

2023 update:

Kindly check your pom.xml file to know what version of java you have configured.

check you java version

<properties>
    <java.version>17</java.version>
</properties>

Then the next thing is to download jdk of the version you have configure. Follow the below step to do that.

enter image description here

  1. Click on file -> Project structure as below
  2. See the image below to add or select Project SDK 3, You can download the specific version of your project if it is missing on the list by clicking Add SDK --> Download JDK. Complete download and apply and click ok to reload application.

enter image description here

eclat_soft
  • 602
  • 7
  • 9
0

In IntelliJ, the default maven compiler version is less than version 5, which is not supported, so we have to manually change the version of the maven compiler.

We have two ways to define version.

First way:

<properties>
  <maven.compiler.target>1.8</maven.compiler.target>
  <maven.compiler.source>1.8</maven.compiler.source>
</properties>

Second way:

<build>
  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
            <source>8</source>
            <target>8</target>
        </configuration>
    </plugin>
  </plugins>
</build>
Pang
  • 9,564
  • 146
  • 81
  • 122
0

guys, I have also encountered this problem after having so much research on this issue I found 3 solutions to resolve this issue

  1. Add these properties in your pom.xml; //Sorry for the formatting

<properties><java.version>1.8</java.version<maven.compiler.version>3.8.1</maven.compiler.version<maven.compiler.source>1.8</maven.compiler.source<maven.compiler.target>1.8</maven.compiler.target><java.version>11</java.version></properties>

  1. Delete everything in the target byte version, you can find this in the java compiler setting of the IntelliJ

Remove everything below target byte version make it empty

  1. Find the appium version you are using in the dependency. here I am using 7.3.0 find the version of the appium you are using in the dependency in pom.xml

Then write your version in the target byte version in java compiler enter image description here

ENJOY THE CODE>>>HOPE IT WORKED FOR YOU

0
For me in Intelij click on File -> Project Structure -> select the modules in language level select 11 - Local variable syntax for lambda parameters, click em aply.

Run in terminal mvn clean install.

Its solved my problem.

Renato Vasconcellos
  • 437
  • 1
  • 6
  • 11
0

For gradle, in addition to setting the jvm version everywhere as described in the answers above, you will also need to set it under Gradle settings: enter image description here

Then change the jvm under Gradle JVM.

jllangston
  • 127
  • 1
  • 5