diff --git a/build.gradle.kts b/build.gradle.kts index 0b60b6c..e713914 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } // Every published version is immutable on the Portal: bump before publishing, and never reuse one. -version = "2.0.0-alpha03" +version = "2.0.0-alpha04-SNAPSHOT" group = "io.github.lemcoder" repositories { diff --git a/src/main/kotlin/io/github/lemcoder/kotlin/KotlinGradlePlugin.kt b/src/main/kotlin/io/github/lemcoder/kotlin/KotlinGradlePlugin.kt index 82f49a9..60aa719 100644 --- a/src/main/kotlin/io/github/lemcoder/kotlin/KotlinGradlePlugin.kt +++ b/src/main/kotlin/io/github/lemcoder/kotlin/KotlinGradlePlugin.kt @@ -36,16 +36,15 @@ internal object KotlinGradlePlugin { /** …and of the main compilation of every JVM and Android target of a multiplatform project. */ fun addKmpJvmSources(project: Project, sources: Provider, generate: TaskProvider<*>, enabled: () -> Boolean) { // Decided when the sources are read, not now: targets are usually declared before konan { }. A - // provider of our own carries no producer, so the compile's dependency is spelled out too. - val lazySources = project.provider { if (enabled()) listOf(sources.get()) else emptyList() } + // provider of our own carries no producer, so the directory is built by the generation explicitly: + // every reader of the source set — the compile, a sources jar, lint — then depends on it. val lazyGenerate = project.provider { if (enabled()) listOf(generate) else emptyList() } + val lazySources = project.files(project.provider { if (enabled()) listOf(sources.get()) else emptyList() }) + .builtBy(lazyGenerate) project.extensions.getByType(KotlinMultiplatformExtension::class.java).targets .matching { it.platformType in JVM_PLATFORMS } .configureEach { - compilations.matching { it.name == "main" }.configureEach { - defaultSourceSet.kotlin.srcDir(lazySources) - compileTaskProvider.configure { dependsOn(lazyGenerate) } - } + compilations.matching { it.name == "main" }.configureEach { defaultSourceSet.kotlin.srcDir(lazySources) } } } diff --git a/src/test/kotlin/io/github/lemcoder/KonanPluginFunctionalTest.kt b/src/test/kotlin/io/github/lemcoder/KonanPluginFunctionalTest.kt index 43044dd..ddc577c 100644 --- a/src/test/kotlin/io/github/lemcoder/KonanPluginFunctionalTest.kt +++ b/src/test/kotlin/io/github/lemcoder/KonanPluginFunctionalTest.kt @@ -936,6 +936,16 @@ class KonanPluginFunctionalTest { assertTrue(":generateJniMymath SKIPPED" in result.output, result.output) } + @Test + fun `a multiplatform jvm() target's sources jar is built after its JNI bindings are generated`() { + write("""kotlin("multiplatform")${"\n"}id("io.github.lemcoder.konanplugin")""", mymath) + File(projectDir, "build.gradle.kts").appendText("kotlin { jvm() }\nrepositories { mavenCentral() }\n") + + val result = runner("jvmSourcesJar", "--dry-run").withPluginClasspathAndKgp().build() + + assertTrue(":generateJniMymath SKIPPED" in result.output, result.output) + } + @Test fun `ffm() serves a multiplatform project's jvm() targets in place of JNI`() { write("""kotlin("multiplatform")${"\n"}id("io.github.lemcoder.konanplugin")""", mymath.replace("library(mymath)", "library(mymath)\n ffm()"))