micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.08k stars 1.07k forks source link

Build native app on macOS without error at kotlin.coroutines.intrinsics.CoroutineSingletons #10771

Closed kurb70 closed 2 weeks ago

kurb70 commented 6 months ago

Expected Behavior

Should build macOS native app without initializing during image building.

Actual Behaviour

I got an error: Classes that should be initialized at run time got initialized during image building: kotlin.coroutines.intrinsics.CoroutineSingletons …

09:40:13: Executing 'nativeBuild'...

Starting Gradle Daemon...
Gradle Daemon started in 686 ms
> Task :generateJte UP-TO-DATE
> Task :compileJava UP-TO-DATE
> Task :compileGroovy NO-SOURCE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar UP-TO-DATE
> Task :generateResourcesConfigFile UP-TO-DATE

> Task :nativeCompile
[native-image-plugin] GraalVM Toolchain detection is disabled
[native-image-plugin] GraalVM location read from environment variable: JAVA_HOME
[native-image-plugin] Native Image executable path: /Users/kuba/.sdkman/candidates/java/21.0.2-graalce/lib/svm/bin/native-image
========================================================================================================================
GraalVM Native Image: Generating 'demo' (executable)...
========================================================================================================================
For detailed information and explanations on the build output, visit:
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
------------------------------------------------------------------------------------------------------------------------
[1/8] Initializing...                                                                                    (7,9s @ 0,27GB)
 Java version: 21.0.2+13, vendor version: GraalVM CE 21.0.2+13.1
 Graal compiler: optimization level: 2, target machine: armv8-a
 C compiler: cc (apple, arm64, 15.0.0)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
 2 user-specific feature(s):
 - com.oracle.svm.thirdparty.gson.GsonFeature
 - io.micronaut.core.io.service.ServiceLoaderFeature
------------------------------------------------------------------------------------------------------------------------
Build resources:
 - 12,09GB of memory (75,6% of 16,00GB system memory, determined at start)
 - 8 thread(s) (100,0% of 8 available processor(s), determined at start)
[2/8] Performing analysis...  [*]                                                                       (73,3s @ 3,69GB)
   36 844 reachable types   (92,9% of   39 648 total)
   59 769 reachable fields  (69,2% of   86 405 total)
  209 421 reachable methods (67,7% of  309 275 total)
   11 157 types,   540 fields, and 7 527 methods registered for reflection
        1 native library: -framework CoreServices

------------------------------------------------------------------------------------------------------------------------
                       33,0s (40,3% of total time) in 93 GCs | Peak RSS: 5,28GB | CPU load: 5,57
========================================================================================================================
Finished generating 'demo' in 1m 21s.
Error: Classes that should be initialized at run time got initialized during image building:
 kotlin.coroutines.intrinsics.CoroutineSingletons was unintentionally initialized at build time. To see why kotlin.coroutines.intrinsics.CoroutineSingletons got initialized use --trace-class-initialization=kotlin.coroutines.intrinsics.CoroutineSingletons
To see how the classes got initialized, use --trace-class-initialization=kotlin.coroutines.intrinsics.CoroutineSingletons

> Task :nativeCompile FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':nativeCompile'.
> Process 'command '/Users/kuba/.sdkman/candidates/java/current/bin/native-image'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1m 26s
6 actionable tasks: 1 executed, 5 up-to-date
09:41:40: Execution finished 'nativeBuild'.

Steps To Reproduce

I created an micronaut 4.4.1 app with

applicationType: default
defaultPackage: com.a0d.care
testFramework: spock
sourceLanguage: java
buildTool: gradle
features: [ app-name, graalvm, gradle, http-client-test, java, java-application, logback, micronaut-aot, micronaut-build, micronaut-http-validation, netty-server, properties, readme, serialization-jackson, shade, spock, static-resources, views-jte ]

and immediately tried to build a native app.

Environment Information

Example Application

No response

Version

4.4.1

sdelamo commented 6 months ago

@msupic could you look into this?

fhussonnois commented 5 months ago

Hi, on one of my projects, I'm currently experiencing the same problem on a Micronaut migration from 4.1.6 to 4.4.2.

Example Application

atrzcinski commented 4 months ago

Is there any workaround for this error?

@sdelamo @msupic

kurb70 commented 2 months ago

I tested it with Micronaut 4.6.0. Unfortunately I still get the same error.

dstepanov commented 2 months ago

It works for me https://github.com/micronaut-projects/micronaut-core/pull/11135 You might need to include graalvm plugin

kurb70 commented 2 months ago

I created a project with

curl --location --request GET 'https://launch.micronaut.io/create/default/com.a0dev.timerecviewer.TimeRecViewer?lang=JAVA&build=GRADLE&test=SPOCK&javaVersion=JDK_21&features=postgres&features=views-jte&features=graalvm' --output TimeRecViewer.zip

and also included include graalvm plugin

When executing nativeBuild fail with this report

20:43:10: Executing 'nativeBuild'...

> Task :generateJte UP-TO-DATE
> Task :compileJava UP-TO-DATE
> Task :compileGroovy NO-SOURCE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :jar UP-TO-DATE
> Task :generateResourcesConfigFile UP-TO-DATE

> Task :nativeCompile
[native-image-plugin] GraalVM Toolchain detection is enabled
[native-image-plugin] GraalVM uses toolchain detection. Selected:
[native-image-plugin]    - language version: 21
[native-image-plugin]    - vendor: GraalVM Community
[native-image-plugin]    - runtime version: 21.0.2+13-jvmci-23.1-b30
[native-image-plugin] Native Image executable path: /Users/kuba/.sdkman/candidates/java/21.0.2-graalce/lib/svm/bin/native-image
========================================================================================================================
GraalVM Native Image: Generating 'TimeRecViewer' (executable)...
========================================================================================================================
For detailed information and explanations on the build output, visit:
https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md
------------------------------------------------------------------------------------------------------------------------
[1/8] Initializing...                                                                                    (7,6s @ 0,37GB)
 Java version: 21.0.2+13, vendor version: GraalVM CE 21.0.2+13.1
 Graal compiler: optimization level: 2, target machine: armv8-a
 C compiler: cc (apple, arm64, 15.0.0)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
 2 user-specific feature(s):
 - com.oracle.svm.thirdparty.gson.GsonFeature
 - io.micronaut.core.io.service.ServiceLoaderFeature
------------------------------------------------------------------------------------------------------------------------
Build resources:
 - 12,09GB of memory (75,6% of 16,00GB system memory, determined at start)
 - 8 thread(s) (100,0% of 8 available processor(s), determined at start)
[2/8] Performing analysis...  [*]                                                                       (88,4s @ 4,63GB)
   37 993 reachable types   (92,9% of   40 877 total)
   61 426 reachable fields  (67,6% of   90 879 total)
  214 448 reachable methods (67,0% of  320 027 total)
   11 505 types,   644 fields, and 7 876 methods registered for reflection
        1 native library: -framework CoreServices

------------------------------------------------------------------------------------------------------------------------
                       35,0s (36,1% of total time) in 99 GCs | Peak RSS: 6,15GB | CPU load: 5,01
========================================================================================================================
Finished generating 'TimeRecViewer' in 1m 36s.
Error: Classes that should be initialized at run time got initialized during image building:
 kotlin.coroutines.intrinsics.CoroutineSingletons was unintentionally initialized at build time. To see why kotlin.coroutines.intrinsics.CoroutineSingletons got initialized use --trace-class-initialization=kotlin.coroutines.intrinsics.CoroutineSingletons
To see how the classes got initialized, use --trace-class-initialization=kotlin.coroutines.intrinsics.CoroutineSingletons

> Task :nativeCompile FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
6 actionable tasks: 1 executed, 5 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':nativeCompile'.
> Process 'command '/Users/kuba/.sdkman/candidates/java/21.0.2-graalce/bin/native-image'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 1m 39s
20:44:50: Execution finished 'nativeBuild'.
dstepanov commented 2 months ago

Can you create and upload the project to GitHub, please?

kurb70 commented 2 months ago

Yes I can, but I created it via https://micronaut.io/launch/ and got there a project ZIP.

curl --location --request GET 'https://launch.micronaut.io/create/default/com.a0dev.timerecviewer.TimeRecViewer?lang=JAVA&build=GRADLE&test=SPOCK&javaVersion=JDK_21&features=postgres&features=views-jte&features=graalvm' --output TimeRecViewer.zip

Do you need more?

gabetrau commented 2 months ago

I got the same graalvm error when trying to use the JTE templates for Micronaut Views. It doesn't occur in other template engines, so maybe it's related to the kotlin jte dependency within micronaut-views-jte

Error: Classes that should be initialized at run time got initialized during image building: kotlin.coroutines.intrinsics.CoroutineSingletons was unintentionally initialized at build time. To see why kotlin.coroutines.intrinsics.CoroutineSingletons

Screenshot from 2024-09-07 02-59-54

dstepanov commented 1 month ago

It looks like we have mistakenly included Kotlin for JTE views.

Please exclude it with:

    implementation("io.micronaut.views:micronaut-views-jte") {
        exclude module: 'jte-kotlin'
    }