Questions : IntelliJ — Invalid source release: 17
2023-02-06T08:45:25+00:00 2023-02-06T08:45:25+00:00
616
I’ve created a new Java project in IntelliJ with Gradle that uses Java 17. When running my app it has the error Cause: error: invalid source release: 17.
My Settings
I’ve installed openjdk-17 through IntelliJ and set it as my Project SDK.
The Project language level has been set to 17 — Sealed types, always-strict floating-point semantics.
In Modules -> Sources I’ve set the Language level to Project default (17 — Sealed types, always strict floating-point semantics).
In Modules -> Dependencies I’ve set the Module SDK to Project SDK openjdk-17.
In Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler I’ve set the Project bytecode version to 17.
Gradle
plugins {
id 'org.springframework.boot' version '2.5.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-websocket'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
}
test {
useJUnitPlatform()
}
I’ve looked at all of the answers here but I can’t seem to fix this. I must be missing something but I can’t find it. I’ve not had any problems using Java 8 or 11.
How do I resolve this?
Total Answers 8
24
Answers 1 : of IntelliJ — Invalid source release: 17
In intellij just set Gradle JVM to Java version 17.
«File -> Settings.. -> Build, Execution, Deployment -> Build Tools -> Gradle»
there select your project and set Gradle JVM to your java 17.0.1
2023-02-06T08:45:25+00:00 2023-02-06T08:45:25+00:00Answer Link
mRahman
5
Answers 2 : of IntelliJ — Invalid source release: 17
The message typically entails that your JAVA_HOME environment variable points to a different Java version.
Here are the steps to follow:
- Close IntelliJ IDEA
- Open a terminal window and check your JAVA_HOME variable value:
- *nix system:
echo $JAVA_HOME
- Windows system:
echo %JAVA_HOME%
- *nix system:
- The JAVA_HOME path should be pointing to a different path, then set it to the openjdk-17 path:
- *nix system:
export JAVA_HOME=/path/to/openjdk-17
- Windows system:
set JAVA_HOME=pathtoopenjdk-17
- *nix system:
- Open your project again in IntelliJ IDEA
- Make sure to set both source and target compatibility versions (not only the
sourceCompatibility
)
You should be able to build your project.
EDIT: Gradle Toolchain
You may need also to instruct Gradle to use a different JVM than the one it uses itself by setting the Java plugin toolchain to your target version:
// build.gradle
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
2023-02-06T08:45:25+00:00 2023-02-06T08:45:25+00:00Answer Link
miraj
1
Answers 3 : of IntelliJ — Invalid source release: 17
Set Gradle JVM to target build jvm
File -> Settings.. ->
2023-02-06T08:45:25+00:00 2023-02-06T08:45:25+00:00Answer Link
jidam
6
Answers 4 : of IntelliJ — Invalid source release: 17
Set JAVA_ HOME TO JDK 17 and check this by Opening cmd -> javac. This should return the current version of java set in your machine
2023-02-06T08:45:25+00:00 2023-02-06T08:45:25+00:00Answer Link
jidam
2
Answers 5 : of IntelliJ — Invalid source release: 17
If you start your project from a main method directly invoked from Intelij then the missing dialog execution configurations may be the cause of the error.
Always check the execution configurations to make sure the correct JRE folder is plugged in. In latest versions of jdk there is not a specific jre folder but the complete jdk package, so make sure it points at this folder.
2023-02-06T08:45:25+00:00 2023-02-06T08:45:25+00:00Answer Link
miraj
5
Answers 6 : of IntelliJ — Invalid source release: 17
you can define org.gradle.java.home in ~/.gradle/gradle.properties like:
org.gradle.java.home=/path/to/jdk17
this will cover both gradle cli and default value for IntelliJ (if not specified otherwise)
(windows users file at C:Users<username>.gradlegradle.properties)
2023-02-06T08:45:25+00:00 2023-02-06T08:45:25+00:00Answer Link
jidam
1
Answers 7 : of IntelliJ — Invalid source release: 17
I was running into this issue, only when building from terminal, while the execution from the IntelliJ Run Configuration works
The reason is probably, that I had downloaded the JDK from the relatively new way of doing it directly from the IDE
My guess is, that this JDK with its path that is set here
Is only known to IntelliJ and likely dynamically passed to Gradle when running a run configuration, and not known to Gradle itself.
I tried to figure out what is happening, so I’ve added this task which in both cases prints the same path to an older local JDK.
tasks.build.doFirst {
println "used jdk path: " + System.getenv('JAVA_HOME')
}
C:Program
FilesGraalVMgraalvm-ce-java11-21.1.0
Afterwards I’ve deleted the old JDK under that path and retried both, run configuration and terminal execution. Now the run configuration still works, while printing the same invalid JDK path, and the terminal execution fails with
ERROR: JAVA_HOME is set to an invalid directory: C:Program
FilesGraalVMgraalvm-ce-java11-21.1.0Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
I had expected the error in both cases, but it seems the JAVA_HOME directory is not necessarily used and in some way other than with the env variable, IntelliJ has to tell Gradle to use the right JDK from the .jdks directory.
This is just an assumption, if anyone has an explanation I’d appreciate it, especially how Gradle is able to know what JDK to use.
2023-02-06T08:45:25+00:00 2023-02-06T08:45:25+00:00Answer Link
jidam
1
Answers 8 : of IntelliJ — Invalid source release: 17
There could be many reasons due to which this error is thrown by intellij
- Check your JAVA_HOME ->
echo $JAVA_HOME
if JAVA_HOME is not correct, update the JAVA_HOME environment variable.
- check if the project structure in IntelliJ is correct.
File > Project Structure > Project Setting > Project -> SDK and Language level should match
File > Project Structure > Project Setting > Modules -> Language Level should match with SDK
- Check and fix settings in preferences are correct
Preferences > Build, Execution and Deployment > Gradle > Gradle JVM should match with SDK (Preferences > Build, Execution and Deployment > maven if you're using maven)
Preferences > Build, Execution and Deployment > Compiler > Java Compiler > Project Bytecode version (this should match with your SDK as well)
2023-02-06T08:45:25+00:00 2023-02-06T08:45:25+00:00Answer Link
joy
I’ve created a new Java project in IntelliJ with Gradle that uses Java 17. When running my app it has the error Cause: error: invalid source release: 17
.
My Settings
I’ve installed openjdk-17
through IntelliJ
and set it as my Project SDK
.
The Project language level
has been set to 17 - Sealed types, always-strict floating-point semantics
.
In Modules -> Sources
I’ve set the Language level
to Project default (17 - Sealed types, always strict floating-point semantics)
.
In Modules -> Dependencies
I’ve set the Module SDK
to Project SDK openjdk-17
.
In Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler
I’ve set the Project bytecode version
to 17
.
Gradle
plugins {
id 'org.springframework.boot' version '2.5.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-websocket'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
}
test {
useJUnitPlatform()
}
I’ve looked at all of the answers here but I can’t seem to fix this. I must be missing something but I can’t find it. I’ve not had any problems using Java 8 or 11.
How do I resolve this?
Я создал новый проект Java в IntelliJ с Gradle, который использует Java 17. При запуске моего приложения возникает ошибка Cause: error: invalid source release: 17
.
Мои настройки
Я установил openjdk-17
через IntelliJ
и установил его как свой Project SDK
.
Project language level
установлен на 17 - Sealed types, always-strict floating-point semantics
.
В Modules -> Sources
я установил Language level
на Project default (17 - Sealed types, always strict floating-point semantics)
.
В Modules -> Dependencies
я установил Module SDK
на Project SDK openjdk-17
.
В Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler
я установил Project bytecode version
на 17
.
Gradle
plugins {
id 'org.springframework.boot' version '2.5.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.app'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-websocket'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
}
test {
useJUnitPlatform()
}
Я просмотрел все ответы здесь но я не могу это исправить. Мне что-то не хватает, но я не могу этого найти. У меня не было проблем с использованием Java 8 или 11.
Как мне решить эту проблему?
3 ответа
Если вы запускаете свой проект из основного метода, непосредственно вызываемого из Intelij, то отсутствующие конфигурации выполнения диалогов могут быть причиной ошибки.
Всегда проверяйте конфигурации выполнения, чтобы убедиться, что подключена правильная папка JRE. В последних версиях jdk нет конкретной папки jre, а всего пакета jdk, поэтому убедитесь, что он указывает на эту папку.
0
Panagiotis Bougioukos
25 Окт 2021 в 11:47
В intellij просто установите Gradle JVM на Java версии 17.
«Файл -> Настройки .. -> Сборка, выполнение, развертывание -> Инструменты сборки -> Gradle» выберите свой проект и установите Gradle JVM на свой java 17.0.1.
4
Rakesh R
3 Дек 2021 в 16:28
Установите JAVA_ HOME в JDK 17 и проверьте это, открыв cmd -> javac. Это должно вернуть текущую версию Java, установленную на вашем компьютере.
0
Virbhadra Kaulwar
24 Окт 2021 в 14:58