Encountering the dreaded “unsupported class file major version 60” error in IntelliJ IDEA can be a frustrating experience, especially when you’re in the middle of a critical project. This error typically arises when your Java Development Kit (JDK) is older than the version used to compile the project’s class files. Essentially, your IntelliJ IDEA is trying to run code compiled with a newer Java version than it currently supports. This situation often occurs after upgrading a project’s dependencies or working on a project with different Java version requirements. Don’t worry; this is a common problem with well-defined solutions. This article provides a comprehensive guide on how to troubleshoot and fix the “unsupported class file major version 60” error, allowing you to get back to coding quickly and efficiently. By understanding the root cause and applying the recommended solutions, you can ensure a smooth development experience within IntelliJ IDEA.
Understanding the “Unsupported Class File Major Version 60” Error
The “unsupported class file major version 60” error is Java’s way of telling you that it can’t execute a class file because it was compiled with a more recent version of the Java compiler than your current Java Runtime Environment (JRE) or JDK supports. The major version number (60 in this case) corresponds to a specific Java version. For example, major version 60 corresponds to Java 16. This means the class file was compiled using Java 16 or later, and your IntelliJ IDEA is configured to use an older version. Therefore, the JVM refuses to load the class file, resulting in the error. Understanding this mismatch is crucial for diagnosing and resolving the issue.
To elaborate, each version of Java comes with a specific class file major version number. When the JVM attempts to load a class file, it checks the major version number to ensure compatibility. If the class file’s major version is higher than what the JVM supports, it throws the “unsupported class file major version” error. This mechanism ensures that newer language features and bytecode instructions are not executed by older JVMs that don’t understand them. This is a safeguard to prevent unpredictable behavior and maintain stability across different Java environments. This often occurs when switching between projects with different Java version requirements. A common scenario is working on a legacy project using Java 8 and then switching to a new project using Java 16 or later.
For example, consider a scenario where you’re contributing to an open-source project. The project maintainers recently upgraded the project to Java 17 to take advantage of new language features. You clone the repository, open it in IntelliJ IDEA, and immediately encounter the “unsupported class file major version 60” error. This indicates that your IntelliJ IDEA is still configured to use an older Java version (e.g., Java 8 or Java 11). To resolve this, you need to update your IntelliJ IDEA’s project settings to use Java 17 or later. Knowing the root cause helps you to avoid unnecessary troubleshooting steps and quickly pinpoint the solution.
Identifying the Java Version Used by IntelliJ IDEA
Before attempting any fixes, it’s essential to determine which Java version IntelliJ IDEA is currently using. This information is crucial for identifying the discrepancy between the project’s required Java version and the IDE’s configuration. There are several ways to check the Java version in IntelliJ IDEA. One of the easiest methods is to check the project structure. Navigate to File -> Project Structure -> Project. Here, you will find the Project SDK, which indicates the Java version being used for the project. Make sure to verify this setting to ensure it aligns with the project’s requirements.
Another way to check the Java version is through the IntelliJ IDEA settings. Go to File -> Settings (or IntelliJ IDEA -> Preferences on macOS) -> Build, Execution, Deployment -> Compiler -> Java Compiler. This section displays the Java compiler settings, including the bytecode target version. This version should match the Java version used to compile the project. If it doesn’t, it can lead to compatibility issues and the “unsupported class file major version” error. It’s also important to check the Java version used by the IntelliJ IDEA itself. This can be found under File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven (if using Maven) or Gradle (if using Gradle). Ensure these settings are consistent across the project and the IDE.
For instance, imagine you checked the Project SDK and found it was set to Java 11, while the project requires Java 16 (major version 60). This mismatch is the direct cause of the error. Similarly, if you’re using Maven or Gradle, ensure that the maven.compiler.source and maven.compiler.target properties in your pom.xml file (or the equivalent settings in your build.gradle file) are set to the correct Java version. According to Oracle, using the correct compiler settings ensures that the generated class files are compatible with the target JRE Oracle Java Downloads. Proper identification of the Java versions involved is the first step towards resolving the “unsupported class file major version” error.
Resolving the “Unsupported Class File Major Version 60” Error
Once you’ve identified the Java version mismatch, you can proceed to resolve the “unsupported class file major version 60” error. The primary solution is to update your IntelliJ IDEA to use a Java Development Kit (JDK) that is compatible with the class file version. Since major version 60 corresponds to Java 16, you need to ensure that IntelliJ IDEA is configured to use Java 16 or a later version. This involves downloading and installing the appropriate JDK and then configuring IntelliJ IDEA to use it.
Here’s a step-by-step guide to update your JDK in IntelliJ IDEA:
- Download the appropriate JDK from a trusted source, such as the Oracle website or Adoptium (Eclipse Temurin). Choose a version that is Java 16 or later.
- Install the JDK on your system, following the instructions provided by the vendor.
- Open IntelliJ IDEA and go to File -> Project Structure -> Project.
- Click on the “New…” button next to the Project SDK dropdown and select “JDK”.
- Browse to the directory where you installed the JDK and select it.
- Apply the changes and rebuild your project.
After updating the Project SDK, you may also need to update the language level. In the same Project Structure window, ensure that the Project language level is set to the appropriate Java version (e.g., 16 or later). Additionally, if you’re using Maven or Gradle, update the maven.compiler.source and maven.compiler.target properties in your pom.xml file (or the equivalent settings in your build.gradle file) to match the new Java version. According to a Stack Overflow survey, ensuring correct project configuration is a key step to avoiding compilation errors Stack Overflow Java. Remember to invalidate caches and restart IntelliJ IDEA (File -> Invalidate Caches / Restart…) after making these changes to ensure that the IDE picks up the new configuration. This step is crucial for clearing out any cached information that might be causing the error.
Advanced Troubleshooting and Configuration
In some cases, simply updating the Project SDK might not be enough to resolve the “unsupported class file major version 60” error. This could be due to several factors, such as incorrect module settings, conflicting dependencies, or outdated plugins. Advanced troubleshooting involves examining these aspects of your project and IntelliJ IDEA configuration.
One common issue is incorrect module settings. Each module in your project can have its own language level and SDK settings. To check these settings, go to File -> Project Structure -> Modules. Select each module and verify that the language level and SDK are set to the correct Java version. If a module is using an older Java version, it can cause compatibility issues even if the project-level settings are correct.
Another potential issue is conflicting dependencies. If your project depends on libraries that were compiled with a different Java version, it can lead to the “unsupported class file major version” error. To resolve this, you need to identify the conflicting dependencies and update them to versions that are compatible with your project’s Java version. Maven and Gradle provide dependency management tools that can help you identify and resolve dependency conflicts. Furthermore, outdated plugins can sometimes cause compatibility issues. Ensure that all your IntelliJ IDEA plugins are up-to-date by going to File -> Settings (or IntelliJ IDEA -> Preferences on macOS) -> Plugins and checking for updates. According to JetBrains, keeping your plugins updated ensures compatibility and access to the latest features IntelliJ IDEA Plugins.
Here are some key points to remember when troubleshooting:
- Double-check all Java version settings in IntelliJ IDEA, including Project SDK, module settings, and compiler settings.
- Use Maven or Gradle to manage dependencies and resolve conflicts.
- Keep your IntelliJ IDEA plugins up-to-date.
Here are some frequently asked questions about the “unsupported class file major version 60” error in IntelliJ IDEA:
- Q: What does "unsupported class file major version 60" mean?
- A: It means your Java Runtime Environment (JRE) or Java Development Kit (JDK) is older than the version used to compile the project's class files. Major version 60 corresponds to Java 16.
- Q: How do I find out what Java version my project is using?
- A: Check the Project SDK in File -> Project Structure -> Project. Also, check the language level and compiler settings in File -> Settings -> Build, Execution, Deployment -> Compiler -> Java Compiler.
- Q: I updated my JDK, but I'm still getting the error. What should I do?
- A: Make sure to update the Project SDK, module settings, and compiler settings in IntelliJ IDEA. Also, invalidate caches and restart IntelliJ IDEA (File -> Invalidate Caches / Restart...). If using Maven or Gradle, update the compiler properties in your pom.xml or build.gradle file.
- Q: Can I use an older Java version to run code compiled with a newer version?
- A: No, you need to use a Java version that is the same as or newer than the version used to compile the code.
- Always keep your JDK and IntelliJ IDEA up-to-date.
- Use a dependency management tool like Maven or Gradle to manage your project’s dependencies.
- Pay attention to the Java version requirements of your projects and dependencies.
If you’ve followed these steps and are still encountering the “unsupported class file major version 60” error, it’s possible that there are other underlying issues, such as corrupted class files or problems with your IntelliJ IDEA installation. In such cases, consider reinstalling IntelliJ IDEA or seeking help from online forums or communities.
The featured snippet-optimized paragraph is: The primary solution to the “unsupported class file major version 60” error is to update your IntelliJ IDEA to use a Java Development Kit (JDK) that is compatible with the class file version. Since major version 60 corresponds to Java 16, you need to ensure that IntelliJ IDEA is configured to use Java 16 or a later version. This involves downloading and installing the appropriate JDK and then configuring IntelliJ IDEA to use it. Ensuring that your IDE aligns with the project requirements is a key step in resolving this issue.
By now, you should have a solid understanding of how to tackle the “unsupported class file major version 60” error in IntelliJ IDEA. Remember to first identify the root cause โ the Java version mismatch. Then, systematically update your project’s SDK, language level, and compiler settings. Don’t forget to invalidate caches and restart IntelliJ IDEA for the changes to take full effect. With these steps, you’ll be well on your way to a smoother, error-free coding experience. To further enhance your IntelliJ IDEA proficiency, explore resources on project setup and dependency management, and consider checking out related articles on optimizing your development environment.
Question & Answer :
I have a Gradle project in Ubuntu. It’s written in Java 14. I have the Java 14 JDK installed. When I build it from the command line, everything works, but no one wants to use a command line! When I open it in IntelliJ IDEA, it throws an error:
* Where: Initialization script '/tmp/ijmapper.gradle` * What went wrong: Could not compile initialization script '/tmp/ijmapper.gradle`. > Startup failed: General error during semantic analysis: Unsupported class file major version 60.
followed by a long, unhelpful stack trace that says a lot about Groovy. (The project is not a Groovy project; it’s a Java project.)
Major version 60 refers to Java 16, which this project is not using. I’ve already gone into Project Structure and made sure that it’s set to use JDK version 14. But the name “ijmapper” suggests that this has something to do with IntelliJ specifically, and this is likely an IDE problem rather than a project problem.
The mapper file simply says:
if(!ext.has('mapPath')) ext.mapPath = { path -> path}
A simple polyfill, in other words.
What’s going on here and how can I fix it?
TL;DR; You need to have the Java version which is compatible with your Gradle version, and configure Gradle to use exactly that version (not older Java, and not even newer version).
I fixed this problem by changing the Gradle JVM settings in IntelliJ settings:
-
In the Settings/Preferences dialog, go to Build, Execution, Deployment โ Build Tools โ Gradle.
-
Under the Gradle section, change the Gradle JVM option. Select a Gradle JVM which works for you.
