Skip to content

fix(whitelist): drop kotlin-reflect via Moshi codegen#5

Merged
lusu007 merged 1 commit intomainfrom
fix/moshi-codegen-no-reflect
May 6, 2026
Merged

fix(whitelist): drop kotlin-reflect via Moshi codegen#5
lusu007 merged 1 commit intomainfrom
fix/moshi-codegen-no-reflect

Conversation

@hbrombeer
Copy link
Copy Markdown
Member

Summary

Plugin `onEnable` crashed with:
```
IllegalStateException: Resource not found in classpath:
gg/grounds/platform/shaded/kotlin/gg.grounds.platform.shaded.kotlin.gg.grounds.platform.shaded.kotlin_builtins
```

ShadowJar's `relocate("kotlin", "gg.grounds.platform.shaded.kotlin")` rewrites the path and the content of every `.kotlin_builtins` resource, producing the triple-prefixed garbage path above. Moshi's `KotlinJsonAdapterFactory` (via `moshi-kotlin`) loads those resources via `kotlin-reflect` on first `adapter()` call, throws `ExceptionInInitializerError`, and Paper disables the plugin — whitelist sync never starts.

Fix: drop reflection from the runtime path entirely.

  • Add `com.google.devtools.ksp` plugin
  • Replace `moshi-kotlin` runtime dep with `moshi-kotlin-codegen` (KSP)
  • Annotate `ListResponse` + `RawEntry` with `@JsonClass(generateAdapter = true)`
  • Remove `KotlinJsonAdapterFactory` from `Moshi.Builder`

KSP generates `ListResponseJsonAdapter` at compile time → no kotlin-reflect on the runtime classpath → no relocation landmine.

Test plan

  • `./gradlew shadowJar` clean (KSP runs, codegen sources compile)
  • `./gradlew test` 4/4 green
  • After merge + 0.1.2 release: re-pull on demo-arena, confirm Paper logs `PluginGroundsPlatform enabled (projectId=…, projectName=…)` instead of the previous `Disabling GroundsPlatform v0.1.0` line

…f the JAR

Plugin onEnable crashed with:
  IllegalStateException: Resource not found in classpath:
  gg/grounds/platform/shaded/kotlin/gg.grounds.platform.shaded.kotlin.gg.grounds.platform.shaded.kotlin_builtins

ShadowJar's `relocate("kotlin", "gg.grounds.platform.shaded.kotlin")`
rewrites the path *and content* of every .kotlin_builtins resource,
producing the triple-prefixed garbage path above. Moshi's
KotlinJsonAdapterFactory (via moshi-kotlin) needs kotlin-reflect to
read those resources at runtime, so adapter() throws
ExceptionInInitializerError as soon as the WhitelistApiClient
constructor runs. Whitelist sync never starts; the entire plugin
gets disabled by Paper.

Drop the reflection path entirely:
  - swap moshi-kotlin runtime dep for moshi-kotlin-codegen via KSP
  - annotate ListResponse + RawEntry with @JsonClass(generateAdapter = true)
  - remove KotlinJsonAdapterFactory from the Moshi.Builder

KSP generates ListResponseJsonAdapter at compile time. No
kotlin-reflect on the runtime classpath, so no relocation
landmine. Same external behaviour, just deserialised by generated
code instead of reflective class scanning.
@lusu007 lusu007 merged commit 5013c2e into main May 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants