beryx / badass-jlink-plugin

Create a custom runtime image of your modular application
https://badass-jlink-plugin.beryx.org
Apache License 2.0
386 stars 27 forks source link

secondary Launcher fails with application main class missing #244

Closed xzel23 closed 9 months ago

xzel23 commented 1 year ago

I try to create a secondary launcher for my JavaFX app. The class com.dua3.docdiff.app.fx.AppMain starts a JavaFX application, com.dua3.docdiff.app.cli.Main is a command line tool that does not use JavaFX. Both classes are in the same module.

I have this in my Kotlin-DSL build file:

    launcher {
        name = "docdiff"
        noConsole = true
        mainClass.set("com.dua3.docdiff.app.fx.AppMain")
        jvmArgs = listOf("-Xms512m", "-Xmx4g", "-XX:+UseG1GC")
    }

    secondaryLauncher {
        name = "docdiffcli"
        noConsole = false
        mainClass.set("com.dua3.docdiff.app.cli.Main")
        jvmArgs = listOf("-Xms512m", "-Xmx2g", "-XX:+UseG1GC")
    }

When I run ./gradlew jpackage, I get the following error:

[10:19:20.369] Anwendungspackage DocDiff.app wird in /Users/axelhowind/IdeaProjects/doc-app/docdiff/app/build/jpackage erstellt
[10:19:20.431] java.lang.RuntimeException: jdk.jpackage.internal.ConfigException: Fehler: Hauptanwendungsklasse fehlt

(This is the localized message, it should translate to "application main class missing".)

Both launchers work if I comment out the other launcher (and replace secondaryLauncher with launcher).

I have not idea what could be wrong since I clearly set mainClass for both launchers.

The versions I am using are Gradle 8.4 and Java 21.0.1, jlink plugin version 3.0.0.

xzel23 commented 1 year ago

OK, after endless headaches (I'm neither an expert in Groovy nor in Kotlin) I found a workaround (tested with version 3.0.0 of the plugin).

Replace the secondaryLauncher block with this:

    val sld = SecondaryLauncherData("docdiffcli")
    sld.mainClass = "com.dua3.docdiff.app.cli.Main"
    sld.noConsole = false
    sld.jvmArgs = listOf("-Xms512m", "-Xmx2g", "-XX:+UseG1GC")
    secondaryLaunchers.add(sld)

I still don't get my head around what exactly is happaning here. But in IntelliJ I can see that the secondaryLauncher expects a LauncherData instance:

image

LauncherData does not have a member called mainclass. So probably something needs to be changed to make secondaryLauncher expect SecondaryLauncherData instead of LauncherData.

airsquared commented 1 year ago

Is it possible this either a bug or misunderstanding with the Kotlin DSL? I'm not able to reproduce this issue by adding these lines to an app built with Groovy DSL:

secondaryLauncher {
    name = "docdiffcli"
    noConsole = false
    mainClass = "com.dua3.docdiff.app.cli.Main"
    jvmArgs = ["-Xms512m", "-Xmx2g", "-XX:+UseG1GC"]
}
xzel23 commented 1 year ago

Yes, seems like something that works different in the Kotlin DSL. However my build file is rather big, with version catalog and all, so I'd rather not go back to groovy (and honestly I don't like Groovy because there are too many ambiguities).

airsquared commented 1 year ago

Could you provide a repository with a minimal reproducible example?

airsquared commented 1 year ago

Found this solution: https://github.com/aya-prover/aya-dev/blob/e9f0854ce4324cb0f1505937bd2e0ecbd3dd7534/ide-lsp/build.gradle.kts#L63

xzel23 commented 1 year ago

I have created a minimal example that exposes the problem.

secondaryLauncher.zip

xzel23 commented 1 year ago

The solution with this as org.beryx.jlink.data.SecondaryLauncherData does not seem to work either in the minimal example.

xzel23 commented 9 months ago

@airsquared I finally had time to look into this and have prepared a PR for this. Please apply.

airsquared commented 9 months ago

Thanks! Merged

ice1000 commented 1 week ago

It's so funny seeing links to Aya in an issue like this! 🤣 thanks for the fix