railwayapp / nixpacks

App source + Nix packages + Docker = Image
https://nixpacks.com
MIT License
2.36k stars 226 forks source link

Add support for Java 20/21 in Java & Scala Providers #1020

Closed marcospereira closed 7 months ago

marcospereira commented 7 months ago

What?

This PR adds Java 20 and 21 support in Java and Scala providers.

Specifically for Scala, it also updates the Eclipse Temurin images to the latest versions.

marcospereira commented 7 months ago

Duh! I now see #1018 exists. This is slightly more comprehensive than that. A reasonable path would be to merge that PR (after adjusting the tests), and then I can add other changes on top of it.

@aleksrutins, makes sense to you?

aleksrutins commented 7 months ago

Yeah, that makes sense.

marcospereira commented 7 months ago

@coffee-cup, sorry for directly pinging you here, but I'm unsure who can approve the workflows to run and add the labels. Can you also take a look at #1021?

aleksrutins commented 7 months ago

Actually, I don't really think my PR has anything that yours don't, so I think that mine could be closed and yours could be merged.

marcospereira commented 7 months ago

Actually, I don't really think my PR has anything that yours don't, so I think that mine could be closed and yours could be merged.

Makes sense to me too. Do you have permission to approve the workflows here, though?

coffee-cup commented 7 months ago

The tests are failing because we need to update the Nix archive version being used for Java. As an example you can look at

It is failing when building

cargo run -- build examples/java-gradle-8 --name gradle

You can set the archive version to something like

59dc10b5a6f2a592af36375c68fda41246794b86

I was experimenting with this before I noticed that this PR existed

image

marcospereira commented 7 months ago

Thanks, @coffee-cup. I made that change, rebased it against the main branch, and running cargo run -- build examples/java-gradle-8 --name gradle works locally for me.

coffee-cup commented 7 months ago

Thank you 🎉

VjekoslavKrainovic commented 7 months ago

I am trying to deploy my Spring Boot Java 21 project but i am getting error that Java 21 is not supported

This is from my Railway log

10 37.95 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project cep-system: Fatal error compiling: error: release version 21 not supported -> [Help 1]

tedyoung commented 7 months ago

@VjekoslavKrainovic I assume you mean "Java 21 is not supported" not "31" which of course doesn't exist.

VjekoslavKrainovic commented 7 months ago

@VjekoslavKrainovic I assume you mean "Java 21 is not supported" not "31" which of course doesn't exist.

Thank you! Fixed

the-devbear commented 7 months ago

I have a similar problem. I'm setting the NIXPACKS_JDK_VERSION enviormental varible to 21 and I'm getting this error

[Region: us-west1]

==============

Using Nixpacks

==============

context: 2556a1571a7cabe6a98664674a419fd0

Nixpacks build failed

Error: Unsupported JDK version: 21
peter-mghendi commented 7 months ago

I have a similar problem. I'm setting the NIXPACKS_JDK_VERSION enviormental varible to 21 and I'm getting this error

[Region: us-west1]

==============

Using Nixpacks

==============

context: 2556a1571a7cabe6a98664674a419fd0

Nixpacks build failed

Error: Unsupported JDK version: 21

I have this same problem while setting the value of NIXPACKS_JDK_VERSION to 21.

brody192 commented 7 months ago

A little fyi, a nixpacks release has not been done that includes this merged PR. if you need support for Java versions 20 and 21 now, you would need to provide a Dockerfile to build your app.

@aleksrutins am I correct in saying the above?

marcospereira commented 6 months ago

Hey, @coffee-cup,

When can we have a release with the changes here? Is there anything else blocking it?

Thanks in advance.

JoaoAccorsi commented 6 months ago

Hi everyone,

Thank you for the details. Just to know whether there is a release date to support Java 20/21 in Railway?

Once trying to deploy a Spring Boot App into Railway, I am also getting the same error:


12.08 [INFO] Total time: 9.659 s 12.08 [INFO] Finished at: 2024-01-22T22:39:43Z 12.08 [INFO] ------------------------------------------------------------------------ 12.08 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project game: Fatal error compiling: error: release version 21 not supported -> [Help 1] 12.08 [ERROR] 12.08 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 12.08 [ERROR] Re-run Maven using the -X switch to enable full debug logging. 12.08 [ERROR] 12.08 [ERROR] For more information about the errors and possible solutions, please read the following articles: 12.08 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException


Thank you for checking this.

Regards, João

tedyoung commented 6 months ago

I recommend using a Dockerfile instead of relying on Railway updating their nixpacks. It's as straightforward as a file like this:

FROM eclipse-temurin:21-jdk as build
COPY . /app
WORKDIR /app
RUN ./mvnw --no-transfer-progress clean 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" ]

I use this in my repo that deploys successfully to Railway: https://github.com/jitterted/ensembler/blob/master/Dockerfile