I am using :
- gradle-2.3
- javac -version = 1.7
- jre = 1.7
- regedit shows it is pointing to 1.7.
But I am still getting below error
Execution failed for task ':compileJava'. > invalid source release: 1.7
Please let me know how to fix it.
I am using :
But I am still getting below error
Execution failed for task ':compileJava'. > invalid source release: 1.7
Please let me know how to fix it.
You can set the JDK Version used by gradle for the build by adding a "gradle.properties" file to your project. Add the following property:
org.gradle.java.home = <Path to the JDK you want to use for your project>
I agree with the previous answer that you also should check if the JDK and the sourceCompatibility match.
Ctrl+Alt+S/Build Tools/Gradle/Gradle JVM
after upgrading JDK. –
Olag You say you are running with Java 7, but are you really sure?
Because as far as I know that error occurs precisely when you are using a source / target level that is not supported by the JVM you are running gradle with. So if I were to take a guess I'd say that gradle seems to think your JDK doesn't support Java 7 (so its JDK 6 or lower)
Maybe double check that
a) Gradle itself is running with JDK 7. If you run gradle from within Eclipse using the STS gradle tooling, it will use the workspace default JRE to run gradle. Check that it is at least a JDK 7. (Go to "Windows >> Preferences >> Java >> Installed JRE". The JRE with a 'check mark' is the one Gradle will run with).
b) Gradle may accidentally pick up another JDK to compile stuff with if it finds an environment variable 'JAVA_HOME'. So double check that it isn't pointing to a JDK 6 or lower.
To check if the $JAVA_HOME
is really to point the default java
echo $JAVA_HOME /usr/lib/jvm/java-1.7.0-openjdk
Check Java version
java -version
openjdk version "1.8.0_151"
If misaligned like above, to modify $JAVA_HOME
in the /etc/profile
(or alternatively the .profile/.bashprofile/ in your user's home directory), let point to
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
BTW: solved at Centos7
to fix Invalid release 1.8
If you have tried all solutions viz -
still you face the issue then check your build.gradle file and look if sourceCompatibility = '17'
is present alone. If yes comment it out.
Try the following in your build gradle:
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
If this does not work please provide the contents of your build.gradle.
In my case Gradle ran on JRE instead of JDK (wrong set of JAVA_HOME). Pointing my JAVA_HOME to the root of the JDK fixed the build. (Of course, assuming your PATH has %JAVA_HOME%\bin)
Reason:
The JDK has the javac for compiling java while the JRE does not.
Just had the "bug" with 1.8 java
Solved: Findbugs showed me an ü in a method title ( not allowed in graddle)
For me I had to change the value of sourceCompatibility
property in build.gradle
file to be something less than or equal current version [I've v. 16, and changed the sourceCompatibility
to v. 11]
It's suggesting that the code is being compiled with a JDK version that doesn't support the specified source level. In mine case I am having jdk version 11 configured on my system but initially in gradle it was 17. So, I need to change it to version 11 in mine build.gradle. (Note:- change both sourceCompatibility and targetCompatibility with the version of jdk you are having in ur system)
java {
sourceCompatibility(JavaVersion.VERSION_11) // 17 ->11
targetCompatibility(JavaVersion.VERSION_11) // 17-> 11
}
You can check Java version defined in JAVA_HOME
variable and build.gradle
file. If both are same this issue go away.
I was using the Android Studio 2021 (Dolphin).
Found that Android Studio 2021 officially supports JDK versions up to JDK 11. While JDK 17 offers newer features and improvements, it might not be fully compatible with Android Studio 2021. I updated to Jellyfish its started working
The issue comes from an unknown java version.
In my case, the sourceCompatibility
and targetCompatibility
wasn't enough.
I had to add this line to change with java 21:
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
And also upgrade gradle version to 8.6
.
© 2022 - 2025 — McMap. All rights reserved.