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

Ответов: 20

Ответы (20)

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

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


  1.8
  1.8

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


  org.apache.maven.plugins
  maven-compiler-plugin
  3.8.1

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.

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

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


    UTF-8
    1.8
    1.8

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


   11

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

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"

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.

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:

 
        1.8
        3.8.1
        1.8
        1.8
    

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                ${maven.compiler.version}
                
                    ${java.version}
                    ${java.version}
                
            
        
    

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


  1.8
  1.8



  org.apache.maven.plugins
  maven-compiler-plugin
  3.8.1

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

1.83.8.11.81.811

  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

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

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.8.0
                
                    11
                
            
        
    
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.

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

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



    1.8
    1.8


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

Within IntelliJ, open pom.xml file.

Add this section before (if your file already has a section, just add the lines below to that existing section):

 
   1.8 
   1.8 

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.

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.

 
      1.8 
      1.8 

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.

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:


  1.8
  1.8

Second way:


  
    
        org.apache.maven.plugins
        maven-compiler-plugin
        3.8.0
        
            8
            8
        
    
  

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


    
        
            org.apache.maven.plugins
            maven-compiler-plugin
            3.8.0  12
        
        
    

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 .iml file (it is created automatically in your project folder if you're using IntelliJ) directly by editing the following line,

From:

To:

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.

2022 WebDevInsider