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

Gradle plugin creates incorrect reflect-config.json entries #269

Closed
jvmusin opened this issue Jul 20, 2022 · 4 comments · Fixed by #289
Closed

Gradle plugin creates incorrect reflect-config.json entries #269

jvmusin opened this issue Jul 20, 2022 · 4 comments · Fixed by #289
Labels
bug Something isn't working gradle-plugin Related to Gradle plugin
Milestone

Comments

@jvmusin
Copy link

jvmusin commented Jul 20, 2022

Describe the bug
In some cases, the plugin creates incorrect reflect-config.json file with an empty parameterTypes for methods.

To Reproduce
Take the attached project, it contains three commits with working (0.9.11) version and non-working (0.9.12 and 0.9.13).
For 0.9.11 version you can have an empty Ktor project with this build.gradle.xml:

plugins {
    application
    kotlin("jvm") version "1.7.10"
    id("org.graalvm.buildtools.native") version "0.9.11" // build resources via "run" command
}

application.mainClass.set("com.example.ApplicationKt")
repositories.mavenCentral()
dependencies {
    implementation("io.ktor:ktor-server-core-jvm:2.0.3")
    implementation("io.ktor:ktor-server-cio-jvm:2.0.3")
    implementation("ch.qos.logback:logback-classic:1.2.11")
}

graalvmNative {
    binaries.named("main") {
        agent.enabled.set(true)
    }
}

To finish the program, please open http://localhost:8080/shutdown in your browser.

It creates `reflect-config with the correct entry:

{
  "name":"ch.qos.logback.core.pattern.PatternLayoutEncoderBase",
  "methods":[{"name":"setPattern","parameterTypes":["java.lang.String"] }]
}

But if you use 0.9.12 with this build.gradle.kts:

plugins {
    application
    kotlin("jvm") version "1.7.10"
    id("org.graalvm.buildtools.native") version "0.9.12" // build resources via "-Pagent run" command
}

application.mainClass.set("com.example.ApplicationKt")
repositories.mavenCentral()
dependencies {
    ...
}

Or 0.9.13 with this:

plugins {
    application
    kotlin("jvm") version "1.7.10"
    id("org.graalvm.buildtools.native") version "0.9.13" // build resources via "run" command
}

application.mainClass.set("com.example.ApplicationKt")
repositories.mavenCentral()
dependencies {
    ...
}

graalvmNative {
    agent.enabled.set(true)
}

Then it creates the entry with an empty parameterTypes property which leads to incorrect configs that we can't use for building a correct image:

{
    "name": "ch.qos.logback.core.pattern.PatternLayoutEncoderBase",
    "methods": [
        {
            "name": "setPattern",
            "parameterTypes": [
                
            ]
        }
    ]
}

Expected behavior
I expect the parameterTypes property to contain java.lang.String.

System Info (please complete the following information):

  • OS: macOS 12.4 Monterey
  • GraalVM Version: 22.1 CE
  • Java Version: 11
  • Plugin version native-gradle-plugin:0.9.13

graalvm-reflect-config-issue.zip

@jvmusin jvmusin added the bug Something isn't working label Jul 20, 2022
@alvarosanchez alvarosanchez added the gradle-plugin Related to Gradle plugin label Jul 21, 2022
@jvmusin
Copy link
Author

jvmusin commented Jul 27, 2022

@alvarosanchez Can I expect the fix in the nearest plugin release? The bug seems critical to me.

@alvarosanchez
Copy link
Collaborator

@gradinac are you aware of changes in the agent stuff in 0.9.12+ that could be causing this?

@jvmusin
Copy link
Author

jvmusin commented Aug 9, 2022

@gradinac Any news on this?

@lazar-mitrovic lazar-mitrovic added this to the 0.9.14 milestone Aug 10, 2022
@gradinac
Copy link
Collaborator

gradinac commented Aug 16, 2022

Sorry for a late answer on this one, I've just come back from vacation.
I think the core issue here lies in NBT's custom metadata post-processing - the generated metadata is further filtered and entry values starting with a certain prefix are removed.
These prefixes default to org.gradle, org.junit, and the problematic one: java
Between 0.9.11 and 0.9.12, I've refactored the then post-processing task into an action that's always added to an instrumented task - it seems like on 0.9.11, this task was never triggered.

@jvmusin As a workaround, if you get a chance, could you try adding the following to the graalvmNative configuration in your build.gradle.kts:

agent.filterableEntries.set(listOf("org.gradle", "org.junit"))

Let me know if it still behaves in the wrong way :)

On the NBT side, I think we should remove the java prefix from the post-processing exclude list. Should we also make this action optional and enabled through a property? cc @melix @lazar-mitrovic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gradle-plugin Related to Gradle plugin
Projects
None yet
4 participants