scalameta / sbt-native-image

Plugin to generate native-image binaries with sbt
251 stars 22 forks source link

Windows native-image error for large classpath #26

Closed RoryStokes closed 3 years ago

RoryStokes commented 3 years ago

Describe the bug

Windows native image builds fail when there are a large number of JARs in the classpath. It looks like previously a single manifest.jar was used to avoid this issue, but this was removed for Windows in #9

To Reproduce Steps to reproduce the behavior:

  1. Create a new SBT project with a large number (~50) of dependencies
  2. Run sbt nativeImage

Expected behavior native-image is invoked to create the binary

Screenshots Instead, the command fails due to the length of the command:

[info] C:\Users\runneradmin\AppData\Local\Coursier\cache\jvm\graalvm-java11@20.2.0\bin\native-image.cmd -cp [long class path here] com.example.MyClass D:\a\my-project\my-project\target\native-image\my-project
 The command line is too long.
[error] native-image command failed with exit code '1'
[error] (my-project / nativeImage) native-image command failed with exit code '1'

Installation:

Additional context I've been able to work around this for now by pre-assembling a fat jar with sbt-assembly, and then overriding the classpath with the result:

fullClasspath in Compile := Seq(Attributed(assembly.value)(AttributeMap.empty)),

Search terms

Windows classpath

olafurpg commented 3 years ago

Thank you for reporting! It would be great to be able to support this for Windows. I can't remember the details of what was failing but I spent quite a long time trying to get it working on Windows with no progress. I don't have a Windows computer to reproduce the issue, which made it even harder to troubleshoot the issue.

olafurpg commented 3 years ago

The manifest jar is always created in Windows but it's not used. The logic is here if anyone wants to take a look https://github.com/scalameta/sbt-native-image/blob/7b4d4d1b9e81da76e944904c2d5a563e7e58ec76/plugin/src/main/scala/sbtnativeimage/NativeImagePlugin.scala#L255-L256

The plugin is enabled in the build itself so you can iterate quickly on the changes with the following workflow

$ sbt # start sbt shell
> example/nativeImage # build native image
# make changes to NativeImagePlugin.scala file
> reload # pick up new changes
> example/nativeImage