micronaut-projects / micronaut-starter

Generates Micronaut applications
Apache License 2.0
213 stars 95 forks source link

The cli application does not work as a native image on GraalVM #2007

Open seanzxx opened 1 year ago

seanzxx commented 1 year ago

Description

The cli application does not work as a native image on GraalVM.

Steps to Reproduce

  1. mn create-cli-app cliapp --features graalvm --build=gradle --lang=kotlin
  2. cd cliapp
  3. ./gradlew -q clean nativeRun

Expected Behaviour

The example exits without any output

Actual Behaviour

The example ends up with Exception:

picocli.CommandLine$InitializationException: Cannot instantiate cliapp.CliappCommand: the class has no constructor
        at picocli.CommandLine$DefaultFactory.create(CommandLine.java:5685)
        at picocli.CommandLine$Model$CommandUserObject.getInstance(CommandLine.java:12263)
        at picocli.CommandLine$Model$CommandSpec.userObject(CommandLine.java:6437)
        at picocli.CommandLine$Interpreter.clear(CommandLine.java:13497)
        at picocli.CommandLine$Interpreter.parse(CommandLine.java:13543)
        at picocli.CommandLine$Interpreter.parse(CommandLine.java:13532)
        at picocli.CommandLine$Interpreter.parse(CommandLine.java:13427)
        at picocli.CommandLine.parseArgs(CommandLine.java:1552)
        at picocli.CommandLine.execute(CommandLine.java:2169)
        at io.micronaut.configuration.picocli.PicocliRunner.run(PicocliRunner.java:137)
        at io.micronaut.configuration.picocli.PicocliRunner.run(PicocliRunner.java:114)
        at cliapp.CliappCommand$Companion.main(CliappCommand.kt:27)
        at cliapp.CliappCommand.main(CliappCommand.kt)
Caused by: java.lang.NoSuchMethodException: cliapp.CliappCommand.<init>()
        at java.base@17.0.8/java.lang.Class.checkMethod(DynamicHub.java:1038)
        at java.base@17.0.8/java.lang.Class.getConstructor0(DynamicHub.java:1204)
        at java.base@17.0.8/java.lang.Class.getDeclaredConstructor(DynamicHub.java:2754)
        at picocli.CommandLine$DefaultFactory.create(CommandLine.java:5656)
        at io.micronaut.configuration.picocli.MicronautFactory.create(MicronautFactory.java:74)
        at picocli.CommandLine$DefaultFactory.create(CommandLine.java:5683)
        ... 12 more

Environment Information

Example Application

cliapp.tar.gz

seanzxx commented 1 year ago

The picocli-codegen is not working with the ksp yet.

https://github.com/remkop/picocli/issues/1564

It works as expected after I use kapt instead.