sbt / sbt-native-packager

sbt Native Packager
https://sbt-native-packager.readthedocs.io/en/stable/
BSD 2-Clause "Simplified" License
1.59k stars 439 forks source link

Cross-compilation with the JLink & Docker plugins #1494

Open demming opened 2 years ago

demming commented 2 years ago

Observed and desired behavior

Using both the JLink an the Docker plugins, when developing on a Mac machine, I'd like to get a Docker image that would run on a Linux machine on a CPU architecture determined by the JDK base image, from which JLink would cherry-pick the required modules.

Right now docker:publishLocal builds the package locally outside Docker, and then injects the resulting package into the Docker image with the JDK/JRE base image for the target platform. This works fine. And I greatly appreciate it. However, the resulting container image is typically relatively large. I'd like to minimize the target JDK/JRE. This issue had come up already in #1449.

Specifically, running moduleName / docker:publishLocal performs the JLink instructions (with a lot of missing transitive dependencies, but that's a different story that I need to investigate more thoroughly) against the local JDK given by javaHome0 in JlinkPlugin.scala#L52.

I need the JLink plugin to run inside a container against the target JDK prior to the copying stage0.

I imagine there should be a way for cross-compiling with JLink to either

At least I can extract the JLink parameter values and pass them on to modified Dockerfile instructions in my build.sbt but this would get all messy with a larger CI configuration and doesn't seem ready for full build automation.

Running the entire sbt workflow inside a container would solve this issue but it would break a lot of tooling and complicate the matters, for example IntelliJ IDEA didn't support it in its 2019 versions.

If there's some simple work-around please point me in the right direction.

Information