Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/io/github/lemcoder/kotlin/KotlinGradlePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Directory>, 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) }
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/test/kotlin/io/github/lemcoder/KonanPluginFunctionalTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()"))
Expand Down
Loading