a year ago
10 14.95 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project attendance-system: Fatal error compiling: error: release version 21 not supported -> [Help 1]
How can I switch from Java 17 to Java 21? Is it not yet available?
4 Replies
a year ago
I recommend moving to building a docker image so that you're not relying on Railway to upgrade their build packs.
This is an example of a Dockerfile that builds an image for a Spring Boot 3.2 and JDK 21 app using Maven (comes from here: https://github.com/jitterted/format-hero/blob/master/Dockerfile)
FROM eclipse-temurin:21-jdk as build
COPY . /app
WORKDIR /app
RUN ./mvnw package -DskipTests
RUN mv -f target/*.jar app.jar
FROM eclipse-temurin:21-jre
ARG PORT
ENV PORT=${PORT}
COPY --from=build /app/app.jar .
RUN useradd runtime
USER runtime
ENTRYPOINT [ "java", "-Dserver.port=${PORT}", "-jar", "app.jar" ]
a year ago
Hello, I don't know if you solved this issue but I got the same and according to https://nixpacks.com/docs/providers/java you can override the default JDK version (17 as of today) with an environment variable called NIXPACKSJDKVERSION; in this case, its value should be 21. Hope you find this helpful!
a year ago
thanks!
variable NIXPACKSJDKVERSION:21 works fine
jitterted
I recommend moving to building a docker image so that you're not relying on Railway to upgrade their build packs. This is an example of a Dockerfile that builds an image for a Spring Boot 3.2 and JDK 21 app using Maven (comes from here: https://github.com/jitterted/format-hero/blob/master/Dockerfile) ``` FROM eclipse-temurin:21-jdk as build COPY . /app WORKDIR /app RUN ./mvnw package -DskipTests RUN mv -f target/*.jar app.jar FROM eclipse-temurin:21-jre ARG PORT ENV PORT=${PORT} COPY --from=build /app/app.jar . RUN useradd runtime USER runtime ENTRYPOINT [ "java", "-Dserver.port=${PORT}", "-jar", "app.jar" ] ```
11 days ago
Should I add anything more than this file?
Because after adding this file my build fails again.
[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------
Jun 05 13:46:46
[INFO] Total time: 6.123 s
Jun 05 13:46:46
[INFO] Finished at: 2025-06-05T08:16:46Z
Jun 05 13:46:46
[INFO] ------------------------------------------------------------------------
Jun 05 13:46:46
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project arfath: Fatal error compiling: error: release version 21 not supported -> [Help 1] [ERROR]
Jun 05 13:46:46
[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]
Jun 05 13:46:46
[ERROR] For more information about the errors and possible solutions, please read the following articles:
Jun 05 13:46:46
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Jun 05 13:46:46
✕ [stage-0 6/7] RUN --mount=type=cache,id=s/18a5dabb-f7f3-4baa-ae04-488c4c8fbab0-m2/repository,target=/app/.m2/repository chmod +x ./mvnw && ./mvnw -DoutputFile=target/mvn-dependency-list.log -B -DskipTests clean dependency:list install
process "/bin/bash -ol pipefail -c chmod +x ./mvnw && ./mvnw -DoutputFile=target/mvn-dependency-list.log -B -DskipTests clean dependency:list install" did not complete successfully: exit code: 1
Jun 05 13:46:46
Dockerfile:19
Jun 05 13:46:46
-------------------
Jun 05 13:46:46
17 | # build phase
Jun 05 13:46:46
18 | COPY . /app/.
Jun 05 13:46:46
19 | >>> RUN --mount=type=cache,id=s/18a5dabb-f7f3-4baa-ae04-488c4c8fbab0-m2/repository,target=/app/.m2/repository chmod +x ./mvnw && ./mvnw -DoutputFile=target/mvn-dependency-list.log -B -DskipTests clean dependency:list install
Jun 05 13:46:46
20 |
Jun 05 13:46:46
21 |
Jun 05 13:46:46
-------------------
Jun 05 13:46:46
ERROR: failed to solve: process "/bin/bash -ol pipefail -c chmod +x ./mvnw && ./mvnw -DoutputFile=target/mvn-dependency-list.log -B -DskipTests clean dependency:list install" did not complete successfully: exit code: 1
Jun 05 13:46:46
Error: Docker build failed