Site icon Adron's Composite Code

Execution failed for task ‘:compileJava’ Quickie Fix

I’ve been doing a lot of Java development lately and this problem seems to rear up at me every time I switch Java or JDK versions. After I found a fix I did a little research and here’s the summary of what happened.

The issue arises in a Java development environment, particularly when using IntelliJ IDEA with Gradle as the build tool. The error message “Execution failed for task ‘:compileJava’. > error: invalid source release: 21” indicates a mismatch between the Java version set in IntelliJ IDEA and the source compatibility version specified in the Gradle build configuration. This problem often occurs when switching between different versions of Java/JDK, as IntelliJ does not always automatically sync the Java version used across the Gradle build system.

What the error looks like in Intellij.

Solution Steps:

1 Verify Current Java Version:

2 Open IntelliJ IDEA Settings:

Finding the Settings, a little different than on Windows running IntelliJ.

3 Adjust Gradle Settings:

4 Set the Correct JDK for Gradle:

This is where I usually need to change the setting for this fix.

5 Apply and Save Changes:

6 Rebuild the Project:

7 Verify the Fix:

Exit mobile version