Maven error trying to build
Author: gwerbinCreated Dec 8, 2025Updated Jan 12, 2026
Preface: I know almost nothing about Java or its tooling. Apologies if this is user error.
I am on MacOS so installed Java using brew install --cask temurin@25 and brew install maven maven-completions.
Then I tried to build the project using ./mvnw clean verify. However I got this error after a lot of package downloading and other output:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] invalid source release 21 with --enable-preview
(preview language features are only supported for release 25)
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.568 s
[INFO] Finished at: 2025-12-08T10:13:39-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.12.1:compile (default-compile) on project average: Compilation failure
[ERROR] invalid source release 21 with --enable-preview
[ERROR] (preview language features are only supported for release 25)
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureExceptionI thought maybe I also needed Java 21, so I installed brew install --cask temurin@21, but I got the same error after that.
Did I do something wrong here? How do I fix this?
Source: gunnarmorling/1brc