Explain Codes LogoExplain Codes Logo

How can I fix "unsupported class file major version 60" in IntelliJ IDEA?

java
gradle
intellij-idea
java-16
Anton ShumikhinbyAnton Shumikhin·Sep 8, 2024
TLDR

To combat the "unsupported class file major version 60" conundrum, realign your IntelliJ project to Java 16.

Steps:

  1. Project SDK: Navigate File > Project Structure > Project, select Java 16 SDK.

  2. Using Maven or Gradle? Fine tune the Java version to 16 in pom.xml or build.gradle files:

    • For Maven:
      <properties> <maven.compiler.source>16</maven.compiler.source> <maven.compiler.target>16</maven.compiler.target> </properties>
    • Gradle at your service:
      java { toolchain { languageVersion.set(JavaLanguageVersion.of(16)) // Levitation...16 levels high! } }
  3. Bring in the big guns: Build > Rebuild Project.

Congrats! Matching of JDK and class file versions fixes the error. Your error just got a taste of its own medicine!

Fix via Gradle: the detailed walkthrough

Upgrade Gradle: Major version 60 indicates Java 16. Updating to Gradle 7.0 or higher ensures everyone gets along:

# gradle-wrapper.properties gets this cool line distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip // Gradle so fast, it comes from the future!

Tuning IntelliJ: Adjust Gradle JVM in IntelliJ; select the JDK version that matches your project:

File > Settings > Build, Execution, Deployment > Build Tools > Gradle

Next, under Gradle JVM, pick the Java version to match with your project - like a puzzle piece!

Environment Variables: Keep JAVA_HOME on the same page with your JDK version:

export JAVA_HOME=/path/to/jdk-16 // Send JAVA_HOME on a guided tour to the JDK 16 town!

Switching JDKs: When hitting the wall, JDK 15 is a good alternative. Its compatibility scores well.

Dependencies Compatibility: Ensure all your aliens, ahem, dependencies, can mingle well with Java 16!

Nailing IntelliJ setup with your JDK

Slight Trickery in Project Structure: IntelliJ IDEA's Project Structure dialog can be a sly fox. Double-check the Module SDK in Modules > Dependencies is set cheerfully to the correct Java SDK.

Refreshing Java Versions: Better close all instances of IntelliJ IDEA or Terminal while making changes - avoiding ghostly caching issues.

Direct Gradle twist in IntelliJ: No luck setting Java 16 from IntelliJ? No worries, build.gradle has your back:

plugins { id 'java' // Did I say java? I meant coffee! } sourceCompatibility = 16 targetCompatibility = 16

Deep dive into Gradle: Initialization scripts, mapper file issues are the hidden gems of Gradle configurations that could surface JVM errors in IntelliJ IDEA.

Gradle Distribution URL chess move: Altering the gradle-wrapper.properties distributionUrl? Double-check the new Gradle version in IntelliJ's Gradle settings - just like confirming your online order!