native-build-tools
native-build-tools copied to clipboard
Gradle plugin creates incorrect `reflect-config.json` entries
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
@alvarosanchez Can I expect the fix in the nearest plugin release? The bug seems critical to me.
@gradinac are you aware of changes in the agent stuff in 0.9.12+ that could be causing this?
@gradinac Any news on this?
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