Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin QuarkusMain native build does not work #29754

Closed
arolfes opened this issue Dec 8, 2022 · 11 comments · Fixed by #29755
Closed

Kotlin QuarkusMain native build does not work #29754

arolfes opened this issue Dec 8, 2022 · 11 comments · Fixed by #29755
Assignees
Labels
area/kotlin kind/bug Something isn't working
Milestone

Comments

@arolfes
Copy link

arolfes commented Dec 8, 2022

Describe the bug

Hello,

I have a main application class and want to compile everything in native mode.

Main Class

package com.github

import io.quarkus.runtime.Quarkus.run
import io.quarkus.runtime.annotations.QuarkusMain

@QuarkusMain
class GreetingApplication

fun main(args: Array<String>) {
    run(*args)
}

during initializing phase it breaks with the following exception:

./gradlew build -Dquarkus.package.type=native

.
.
.

========================================================================================================================
GraalVM Native Image: Generating 'quarkus-kotlin-native-1.0.0-SNAPSHOT-runner' (executable)...
========================================================================================================================
[1/7] Initializing...                                                                                    (0.0s @ 0.15GB)
Error: Method 'com.github.GreetingApplication.main' is declared as the main entry point but it can not be found. Make sure that class 'com.github.GreetingApplication' is on the classpath and that method 'main(String[])' exists in that class.
com.oracle.svm.core.util.UserError$UserException: Method 'com.github.GreetingApplication.main' is declared as the main entry point but it can not be found. Make sure that class 'com.github.GreetingApplication' is on the classpath and that method 'main(String[])' exists in that class.
 

Expected behavior

native build works also with a kotlin main class

Actual behavior

Build breaks during Initialization Phase with this error message:

[1/7] Initializing... (0.0s @ 0.15GB)
Error: Method 'com.github.GreetingApplication.main' is declared as the main entry point but it can not be found. Make sure that class 'com.github.GreetingApplication' is on the classpath and that method 'main(String[])' exists in that class.
com.oracle.svm.core.util.UserError$UserException: Method 'com.github.GreetingApplication.main' is declared as the main entry point but it can not be found. Make sure that class 'com.github.GreetingApplication' is on the classpath and that method 'main(String[])' exists in that class.

How to Reproduce?

  1. clone the sample repo: https://github.com/arolfes/quarkus-kotlin-native
  2. run nativeBuild ./gradlew build -Dquarkus.package.type=native

Output of uname -a or ver

Linux fedora 6.0.11-300.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Dec 2 20:47:45 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.14.3.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle 7.5.1

Additional information

No response

@arolfes arolfes added the kind/bug Something isn't working label Dec 8, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Dec 8, 2022

/cc @evanchooly, @geoand

@geoand
Copy link
Contributor

geoand commented Dec 8, 2022

Thanks for reporting.

#29755 fixes the issue

@arolfes
Copy link
Author

arolfes commented Dec 8, 2022

That was fast.
thank you

@geoand
Copy link
Contributor

geoand commented Dec 8, 2022

👍

@evanchooly
Copy link
Member

Does this work in JVM mode? because GreetingApplication is an empty class and contains no functions. that main() belongs to a class called <FileName>kt. If the file name just happens to be GreetingApplication.kt then perhaps you're getting this association for free but I would consider a class set up this way to be a bug in the application itself. (I haven't seen @geoand's PR yet so maybe the fix is simple.)

geoand added a commit to geoand/quarkus that referenced this issue Dec 8, 2022
geoand added a commit to geoand/quarkus that referenced this issue Dec 8, 2022
geoand added a commit to geoand/quarkus that referenced this issue Dec 8, 2022
@arolfes
Copy link
Author

arolfes commented Dec 8, 2022

Hello @evanchooly ,

the problem exists also in the normal run mode. you can't start.

2022-12-08 19:48:41,477 INFO  [io.qua.dep.dev.IsolatedDevModeMain] (main) Attempting to start live reload endpoint to recover from previous Quarkus startup failure
> :qu2022-12-08 19:48:41,725 ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.NoSuchMethodException: com.github.GreetingApplication.main([Ljava.lang.String;)
        at java.base/java.lang.Class.getMethod(Class.java:2227)
        at io.quarkus.runner.bootstrap.StartupActionImpl.runMainClass(StartupActionImpl.java:98)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:137)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:447)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:59)
        at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:149)
        at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:104)
        at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:131)
        at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:62)

@geoand : Does your commit fix this problem also? Or should I open a new bug report?

@evanchooly
Copy link
Member

evanchooly commented Dec 9, 2022

That's precisely my point. This main() doesn't exist on GreetingApplication. At best it exists on GreetingApplicationKt because the main() is a top level function. If you want this precise source to work try updating your annotation like so: @file:QuarkusMain. That will apply the annotation to the file and thus, potentially, the GreetingApplicationKt class synthesized to hold your top level function.

In short, this is not a quarkus bug and should not be fixed in quarkus. This is a function of how kotlin works and thus not a bug at all but a misunderstanding how where elements live and how to annotate them properly.

@geoand
Copy link
Contributor

geoand commented Dec 9, 2022 via email

@geoand
Copy link
Contributor

geoand commented Dec 9, 2022

@evanchooly I don't agree that this should not be fixed.

Users expect to do something like:

@SpringBootApplication
class DemoApplication

fun main(args: Array<String>) {
    runApplication<DemoApplication>(*args)
}

because that's how they are told to do it in Spring Boot.
We should seamlessly support this same intuitive pattern. My PR does take care of it, while also allowing for the more verbose syntax with the companion object.

@arolfes
Copy link
Author

arolfes commented Dec 9, 2022

Thanks for clarification

@evanchooly
Copy link
Member

If that's how Spring does it then perhaps being consistent with that has its merits. Spring made the wrong choice there, IMO, as this changes the semantics of the language.

geoand added a commit that referenced this issue Dec 9, 2022
Fix combination of @QuarkusMain and Kotlin native application
@quarkus-bot quarkus-bot bot added this to the 2.16 - main milestone Dec 9, 2022
@gsmet gsmet modified the milestones: 2.16 - main, 2.15.1.Final Dec 20, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kotlin kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants