I have a very simple Scala project with ONLY the Scala library as dependency and using the assembly plugin to create a jar. SBT is:
name := "Bigjar"
version := "1.0.0"
scalaVersion := "3.4.2"
assembly / assemblyMergeStrategy := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case "reference.conf" => MergeStrategy.concat
case x => MergeStrategy.first
}
build.properties is:
sbt.version=1.10.0
assembly.sbt is:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.2.0")
Now:
native-image -jar target/scala-3.4.2/bigjar.jar
gives me:
========================================================================================================================
GraalVM Native Image: Generating 'bigjar' (executable)...
========================================================================================================================
[1/8] Initializing... (19.2s @ 0.11GB)
Java version: 22.0.2+9, vendor version: Oracle GraalVM 22.0.2+9.1
Graal compiler: optimization level: 2, target machine: armv8-a, PGO: off
C compiler: cc (apple, arm64, 14.0.3)
Garbage collector: Serial GC (max heap size: 80% of RAM)
2 user-specific feature(s):
- com.oracle.svm.polyglot.scala.ScalaFeature
- com.oracle.svm.thirdparty.gson.GsonFeature
------------------------------------------------------------------------------------------------------------------------
Build resources:
- 6.05GB of memory (75.6% of 8.00GB system memory, determined at start)
- 8 thread(s) (100.0% of 8 available processor(s), determined at start)
[2/8] Performing analysis... [***] (17.5s @ 0.55GB)
6,236 reachable types (78.8% of 7,909 total)
7,809 reachable fields (49.9% of 15,646 total)
33,070 reachable methods (46.8% of 70,627 total)
1,840 types, 63 fields, and 817 methods registered for reflection
59 types, 57 fields, and 53 methods registered for JNI access
4 native libraries: -framework Foundation, dl, pthread, z
[3/8] Building universe... (1.6s @ 0.65GB)
Warning: Reflection method java.lang.Class.getMethods invoked at scala.Enumeration.populateNameMap(Enumeration.scala:201)
Warning: Reflection method java.lang.Class.getDeclaredFields invoked at scala.Enumeration.getFields$1(Enumeration.scala:195)
Warning: Reflection method java.lang.Class.getDeclaredFields invoked at scala.Enumeration.getFields$1(Enumeration.scala:195)
Warning: Reflection method java.lang.Class.getDeclaredFields invoked at scala.Enumeration.populateNameMap(Enumeration.scala:197)
Warning: Aborting stand-alone image build due to reflection use without configuration.
------------------------------------------------------------------------------------------------------------------------
1.6s (4.2% of total time) in 449 GCs | Peak RSS: 0.97GB | CPU load: 3.33
========================================================================================================================
Failed generating 'bigjar' after 38.6s.
Generating fallback image...
Warning: Image 'bigjar' is a fallback image that requires a JDK for execution (use --no-fallback to suppress fallback image generation and to print more detailed information why a fallback image was necessary).
I tried everything in GraalVM’s docs regarding solving the above reflection issue but to no avail (Docs).
I don’t use any Enumerations as the process describes above so it can only be a consequence of something in the Scala library itself.
What gives? Is the Scala library in itself with intractable reflections impossible to resolve outside of runtime? Do I need to get off Scala to be able to generate native code?
J Kos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.