Error:java: invalid flag: -release
Asked Answered
R

14

37

I use Java :

Java(TM) SE Runtime Environment (build 9-ea+143) Java HotSpot(TM) 64-
Bit Server VM (build 9-ea+143, mixed mode)

and IntelliJ IDEA:

IntelliJ IDEA 2016.2.5 Build #IU-162.2228.15, built on October 14,
2016

Get error when compiling:

Error:java: invalid flag: -release

Executing javac -help :

--release <release>
        Compile for a specific VM version. Supported targets: 6, 7, 8, 9

So javac should use two hyphens with release, but Intellij Idea use with one.

Can I override javac options that IDEA use or fix it in some way?

UPD: Even Build, Execution, Deployment > Compiler > Java Compiler Additional Command Line Parameter doesn't help in this case

Rowlock answered 6/11, 2016 at 10:38 Comment(8)
You can change compiler settings in Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler.Dilemma
@fRoStBiT i know about this option - but now success with it- still Error:java: invalid flag: -releaseRowlock
Have you tried to use Eclipse Compiler?Dilemma
Got weird NPE in case of Eclipse CompilerRowlock
Have you tried 2016.3 (currently in Public Preview)?Therrien
@NicolaiParlog just have downloaded IDEA today and it was 2016.2.5Rowlock
Java 9 support is cutting edge so maybe it's better in the coming version - why not give it a try?Therrien
@NicolaiParlog now it works correct! thanks! I even don't have to specify --module-path in compiler = ) btw IDEA doesn't recognize java.lang classes automatically, but compilation is success. Could you present you tip as an answer to allow me mark it as correct and close question?Rowlock
T
9

Java 9 support is cutting edge and should be tried with the most current version. At the moment, this is the public preview of 2016.3, available here.

Therrien answered 7/11, 2016 at 10:57 Comment(3)
I'm running IntelliJ 2017.1.3 and getting the same error.Slub
Try version 2017.3.4 or above.Mccandless
I'm runningIntelliJ 2023.2.1 and getting the same error.Lucielucien
M
31

I was using Java 8 and Intellij 2018.1.1

I solved the issue in this way:

  • open IntelliJ Idea settings
  • navigate to Build, Execution, Deployment > Compiler > Java Compiler
  • Uncheck the option: Use '--release' option for cross-compilation (Java 9 and later)

Intellij Settings

Montmartre answered 18/4, 2018 at 17:12 Comment(1)
I Had to do the opposite, check the option, select project bytecode version 9.Horeb
T
9

Java 9 support is cutting edge and should be tried with the most current version. At the moment, this is the public preview of 2016.3, available here.

Therrien answered 7/11, 2016 at 10:57 Comment(3)
I'm running IntelliJ 2017.1.3 and getting the same error.Slub
Try version 2017.3.4 or above.Mccandless
I'm runningIntelliJ 2023.2.1 and getting the same error.Lucielucien
H
8

Had exactly the same Error:java: invalid flag: -release in Intellij 2017.1. Updating to 2017.2.5 resolves the issue.

Haematogenesis answered 12/11, 2017 at 2:47 Comment(0)
Q
6

Can be caused by mismatch of java version on build configuration and module settings.

Quadrate answered 12/3, 2018 at 17:13 Comment(3)
Can you explain that further (if needed with reference)? Right now, your answer is very broad.Eglantine
He is right; if you have java 11 and javafx8, you can well run into problems.Milling
The error appear when on pom: <properties><java.version>11</..> but JAVA_HOME points to jdk 1.8Accord
T
4

As specified in this intellij thread you can workaround it by setting the project SDK language level to x - Experimental Features

Tumer answered 15/1, 2018 at 13:46 Comment(0)
N
3

This issue also occurs when java version used to build is not compatible with spring boot version, as for example spring boot version 3.1.0 requires java 17.If project is created with spring boot version 3.1.0 and later in pom.xml java version is downgraded to 1.8 or 11 to build with 1.8 or 11 respectively then you will get this error. So to avoid this create your project with lower spring boot version which supports your java version

Naidanaiditch answered 9/6, 2023 at 7:34 Comment(0)
D
2

I had the same problem with IntelliJ IDEA Version 2017.1.3

Updated IntelliJ to Version: 2017.3.4 and with the latest version it works fine.

Detergency answered 22/2, 2018 at 10:43 Comment(0)
T
2

Remove --warning-mode=all (File -> Setting -> Build, Execution, Deployment -> Java Compiler

ViewImage:
ViewImage

Transparency answered 17/9, 2019 at 20:4 Comment(0)
S
2

Remove the release tag in configuration of maven-compiler-plugin

    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
            ... #here
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
Stannary answered 18/5, 2022 at 15:58 Comment(0)
A
2

This is valid only if you're using Gradle(Not maven). Changing the Gradle JVM to Java 11 matching my $JAVA_HOME value worked for me.

Gradle preferences

Allahabad answered 12/1, 2023 at 21:42 Comment(0)
G
1

You can check the JDK version, if its less than JDK8, upgrade and try again. It solved my issue.

Gynecium answered 10/2, 2020 at 11:46 Comment(0)
O
1

--release is a new option in JDK >= 9 versions

Oddball answered 27/8, 2022 at 18:38 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Crystalcrystalline
D
1

For me, the problem cleared once I set my environment variable JAVA_HOME=%JAVA_HOME_8%

(Note: JAVA_HOME_8 and JAVA_HOME_11 are env variables that I've created myself to point to their respective versions and easily switch between). Maven (i'm using 3.8.6) seems to point the jdk using the JAVA_HOME environment variable. So even if the IDE and the pom is properly configured, depending on how your compiler/build/run plugins are setup, maven may still manage to feed off of the JAVA_HOME variable)

I've also done the following:

  • Modify the pom with java.version as "8"
  • Modify the project sdk to 1.8 (via project structure dialog)
  • uncheck the cross-compliation flag as mentioned in the primary solution.
Desiccator answered 8/9, 2022 at 12:48 Comment(0)
L
1

The -release flag is for JDK 9 and above. Please view the article from Baeldung.com: Set the Java version in .pom file from project/Setting the Java Version in Maven, the answer is based on this article.

Personally I have the following versions active.

Maven

Apache Maven 3.3.9

Java

jdk1.8.0_202, version 1.8.0_202, vendor: Oracle Corporation

IntelliJ

IntelliJ IDEA 2022.3.1 (Ultimate Edition)

In my case, I wanted to compile a library project to Java version 8, so I changed the source and target to 1.8. If you have a higher version of Java active on your computer, you should be able to build lower Java version projects as long as you specifically specify it in the .pom file of the project.

Note: "What's more, we don't need a JDK 7 installed in our machine. Java 9 already contains all the information for linking the new language features with JDK 7" from Set the Java version in .pom file from project/Setting the Java Version in Maven.

  1. Set maven.compiler.source and maven.compiler.target project properties to the Java version you want the classes to compile to: enter image description here

  2. Set the maven-compiler-plugin source and target to Java 8 (you can also use the ${maven.compiler.source} and ${maven.compiler.source} as the version). enter image description here

This should fix the error, assuming you are using a working Java JDK with proper support.

Lymphadenitis answered 27/3, 2023 at 9:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.