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:

  • Open a terminal or command prompt.
  • Run java -version to check the installed Java version.

2 Open IntelliJ IDEA Settings:

  • Launch IntelliJ IDEA.
  • Navigate to File -> Settings (or IntelliJ IDEA -> Preferences on macOS).
Continue reading “Execution failed for task ‘:compileJava’ Quickie Fix”