Skip to content

fix: generated KMP JNI sources carry their producer - #15

Merged
lemcoder merged 2 commits into
feature/konan-dslfrom
fix/kmp-generated-sources-producer
Nov 2, 2026
Merged

lemcoder merged 2 commits into
feature/konan-dslfrom
fix/kmp-generated-sources-producer

Conversation

@lemcoder

@lemcoder lemcoder commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Problem

KotlinGradlePlugin.addKmpJvmSources adds the generated JNI bindings to every JVM/Android main source set through project.provider { … }, which carries no producer, and only patches the compile tasks with dependsOn(generate). Any other reader of the source set races generation. Publishing a KMP library with an Android target (vanniktech maven-publish, androidSourcesJar) fails:

Task ':soundfont:androidSourcesJar' uses this output of task ':soundfont:generateJniTsf' without declaring an explicit or implicit dependency.

Fix

The source directory is a project.files(…).builtBy(generate) collection, so the compile, sources jars, lint and anything else reading the source set depend on generation. The compile-only dependsOn is no longer needed.

Tests

  • New: a multiplatform jvm() target's sources jar is built after its JNI bindings are generated. It fails without the fix and passes with it.
  • Existing a multiplatform jvm() target compiles after its JNI bindings are generated still passes.
  • Checked in MikroSoundFont (Android-KMP library, AGP 9.3.1) via includeBuild: androidSourcesJar now depends on generateJniTsf without the build-script workaround.

🤖 Generated with Claude Code

lemcoder and others added 2 commits November 2, 2026 01:35
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
addKmpJvmSources added the generated directory through a provider of its own,
which carries no producer, and patched only the compile tasks with dependsOn.
Any other reader of the source set raced generation: a published Android or
jvm() sources jar failed Gradle's implicit-dependency check. The directory is
now a file collection built by the generation task, so every reader depends on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lemcoder
lemcoder changed the base branch from main to feature/konan-dsl November 2, 2026 21:40
@lemcoder
lemcoder merged commit fe711e6 into feature/konan-dsl Nov 2, 2026
2 checks passed
lemcoder added a commit to lemcoder/MikroSoundFont that referenced this pull request Nov 2, 2026
alpha04 orders its tasks after KGP's downloadKotlinNativeDistribution
(lemcoder/KonanPlugin#16) and gives the generated JNI sources their
producer (lemcoder/KonanPlugin#15), so the build script needs neither
dependency. It also marshals JNI strings as real UTF-8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant