Fix Maven Invalid Target Release and Source Option Errors
Fix invalid target release and source option errors by setting maven.compiler.release, updating the compiler plugin and making Maven run on the right JDK.

Two messages cover most of this category:
[ERROR] Source option 5 is no longer supported. Use 8 or later.
[ERROR] Target option 5 is no longer supported. Use 8 or later.[ERROR] Fatal error compiling: error: invalid target release: 21The first says the build asks for Java 5, which a modern JDK refuses. The second says the build asks for Java 21 and the JDK that Maven runs on does not know it. Opposite problems with the same fix: say clearly which version you want, and run on a JDK that supports it. The surrounding failure is covered in compiler plugin errors.
Source option 5 is no longer supported
The compiler plugin (before version 3.8) defaults source and target to 1.5 when you set nothing. A POM that never configured the Java version then asks for Java 5, and a current JDK (which dropped support for 5, 6 and 7 over time) says no. Set the version:
<properties>
<maven.compiler.release>21</maven.compiler.release>
</properties>Also update the plugin so its defaults are sane:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>Spring Boot's parent POM manages the plugin version and java.version, so a Boot project sets <java.version>21</java.version> instead.
Invalid target release: 21
Maven runs on JDK 17, the POM says 21. Check:
./mvnw -vThe output lists Maven home, Java version and Java home. If the Java version is older than the one you ask for, switch the JDK Maven uses:
export JAVA_HOME=$(/usr/libexec/java_home -v 21) # macOS
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 # Linux, example pathThen rerun. In an IDE, the Maven run configuration can use a different JDK from the terminal: check the "Maven runner JRE" setting. The environment errors are in the JAVA_HOME fix, and the Java class file side in class file version mismatch.
release versus source and target
| Setting | Language level | Bytecode version | Checks API against |
|---|---|---|---|
maven.compiler.source + target | Set | Set | The running JDK's classes |
maven.compiler.release | Set | Set | The target release's API |
With source and target, compiling on JDK 25 for Java 17 lets your code call a method added in Java 21, and it compiles, then fails at runtime on Java 17. release (available since Java 9) makes the compiler reject that call. Use release whenever the JDK that builds is newer than the one that runs. For Java 8 targets, release 8 also works from JDK 9 onward.
A multi-module project
In a multi-module build, set the property once in the parent POM and let children inherit it. A child that declares its own <source>1.8</source> in plugin configuration overrides the property. Search for <source> and <target> across the project:
grep -rn "<source>\|<target>\|compiler.source\|compiler.target" --include=pom.xml .Replace them with release.
Toolchains
A team where each developer has a different default JDK should pin the build JDK with a Maven toolchain, so the compiler version no longer depends on JAVA_HOME:
<plugin>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<toolchains>
<jdk><version>21</version></jdk>
</toolchains>
</configuration>
<executions><execution><goals><goal>toolchain</goal></goals></execution></executions>
</plugin>with a ~/.m2/toolchains.xml listing the installed JDKs.
Class file versions and the JDK that produced them
An error that mentions a version number is easier to read with the table of numbers. Each Java release writes a class file with a major version, and a JDK refuses to run or compile for a number higher than it knows:
| Java | Class file major version |
|---|---|
| 8 | 52 |
| 11 | 55 |
| 17 | 61 |
| 21 | 65 |
| 25 | 69 |
A message such as class file has wrong version 65.0, should be 61.0 says that a jar compiled for Java 21 is being used by a Java 17 runtime. Upgrade the runtime, or ask the library for a build that targets an older Java. The message Unsupported class file major version 69 from a build plugin means the plugin's bytecode library is older than the JDK, and the fix is a newer plugin.
Find out which JDK Maven really uses
The java on the path and the JDK Maven uses are not always the same, and the second is the one that counts:
./mvnw -v
echo $JAVA_HOMEThe first command prints Java version and runtime home. A build that works in the IDE and fails on the command line commonly has two different JDKs: the IDE's project SDK is 21 and JAVA_HOME is 11. Fix JAVA_HOME, or pin the JDK for the repository in .mvn/jvm.config for flags, or with a toolchain for the compiler.
Prefer release over source and target
The release option sets the language level, the class file version and the API that the code may call, all at once. source and target do the first two and leave the library API open, so code can compile against a method that does not exist on the older Java it claims to support:
<properties>
<maven.compiler.release>17</maven.compiler.release>
</properties>With release set to 17 on a JDK 25, String.stripIndent compiles and a Java 21 method does not, with cannot find symbol. That failure is the check working. Remove source and target when release is set, because Maven warns when both appear, and an old value in a parent POM can override the intended one.
Where the old value hides
When the error says Java 5 or 1.5 and no file in the project mentions it, search the effective configuration:
./mvnw help:effective-pom | grep -nE 'compiler|release|source|target' | head -20The default of an old maven-compiler-plugin version is 1.5 or 1.6, and a parent POM or a plugin management section that pins the plugin to an ancient release brings it back. Declare the plugin explicitly with a current 3.x version, and the default no longer applies. Spring Boot projects with the Boot parent set java.version, and the compiler release follows it, so one property is enough.
Check the CI image as well
A pipeline that builds in a container with an older JDK produces these errors for a branch that builds locally. Print java -version and mvn -v at the start of the CI job, so the log shows the answer. Pin the image tag to a specific JDK version, and update it in the same pull request that raises release.
A checklist for a new machine or job
Most of these errors appear when someone sets up a machine. A short checklist avoids them: install a JDK that matches the project's release, set JAVA_HOME to it, check that mvn -v reports the same JDK, and run ./mvnw -q -DskipTests verify once before touching code. In CI, print java -version and mvn -v at the start of every job.
Add the checklist to the README. A new developer who follows it gets a working build in ten minutes and does not need to ask in the team chat.
Where this does not apply
If the release flag is right and the build still fails, check for another plugin that carries its own Java version (Kotlin, Scala, AspectJ). The [compiler plugin documentation on release](https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-release.html) and the toolchains guide are the primary sources.


