Unverified Commit faca8b45 authored by Ivan Matkov's avatar Ivan Matkov Committed by GitHub

Add AWT runtime artifact constraints to prevent incompatibilities (#1155)

Fixes [SKIKO-1101](https://youtrack.jetbrains.com/issue/SKIKO-1101)
Prevent possible version mismatch between skiko Kotlin and JNI parts
parent a323fb11
...@@ -196,6 +196,7 @@ object SkikoArtifacts { ...@@ -196,6 +196,7 @@ object SkikoArtifacts {
// names are also used in samples, e.g. samples/SkijaInjectSample/build.gradle // names are also used in samples, e.g. samples/SkijaInjectSample/build.gradle
val commonArtifactId = "skiko" val commonArtifactId = "skiko"
val jvmArtifactId = "skiko-awt" val jvmArtifactId = "skiko-awt"
val jvmRuntimeArtifactId = "skiko-awt-runtime"
// an artifact (klib) for k/js targets // an artifact (klib) for k/js targets
val jsArtifactId = "skiko-js" val jsArtifactId = "skiko-js"
// an artifact (klib) for k/wasm targets // an artifact (klib) for k/wasm targets
......
...@@ -18,6 +18,12 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType ...@@ -18,6 +18,12 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
private val SkikoProjectContext.publishing get() = project.extensions.getByType(PublishingExtension::class.java) private val SkikoProjectContext.publishing get() = project.extensions.getByType(PublishingExtension::class.java)
private val awtRuntimeTargets = listOf(
OS.MacOS to Arch.X64, OS.MacOS to Arch.Arm64,
OS.Linux to Arch.X64, OS.Linux to Arch.Arm64,
OS.Windows to Arch.X64, OS.Windows to Arch.Arm64
)
private class SkikoPublishingContext( private class SkikoPublishingContext(
val projectContext: SkikoProjectContext, val projectContext: SkikoProjectContext,
) { ) {
...@@ -43,6 +49,7 @@ fun SkikoProjectContext.declarePublications() { ...@@ -43,6 +49,7 @@ fun SkikoProjectContext.declarePublications() {
ctx.configurePublicationDefaults() ctx.configurePublicationDefaults()
ctx.configureAllJvmRuntimeJarPublications() ctx.configureAllJvmRuntimeJarPublications()
ctx.configureAwtRuntimeJarPublication() ctx.configureAwtRuntimeJarPublication()
ctx.configureAwtPublicationConstraints()
ctx.configureAdditionalRuntimeLibrariesPublication() ctx.configureAdditionalRuntimeLibrariesPublication()
ctx.configureWebPublication() ctx.configureWebPublication()
ctx.configureAndroidPublication() ctx.configureAndroidPublication()
...@@ -87,7 +94,7 @@ private fun SkikoPublishingContext.configurePublishingRepositories() { ...@@ -87,7 +94,7 @@ private fun SkikoPublishingContext.configurePublishingRepositories() {
} }
private fun SkikoPublishingContext.configurePublicationDefaults() { private fun SkikoPublishingContext.configurePublicationDefaults() {
pomNameForPublication["kotlinMultiplatform"] = "Skiko MPP" pomNameForPublication["kotlinMultiplatform"] = "Skiko KMP"
kotlin.targets.forEach { kotlin.targets.forEach {
pomNameForPublication[it.name] = "Skiko ${toTitleCase(it.name)}" pomNameForPublication[it.name] = "Skiko ${toTitleCase(it.name)}"
} }
...@@ -144,7 +151,7 @@ private fun SkikoPublishingContext.configureAllJvmRuntimeJarPublications() = pub ...@@ -144,7 +151,7 @@ private fun SkikoPublishingContext.configureAllJvmRuntimeJarPublications() = pub
.appendNode("dependency").apply { .appendNode("dependency").apply {
appendNode("groupId", SkikoArtifacts.groupId) appendNode("groupId", SkikoArtifacts.groupId)
appendNode("artifactId", SkikoArtifacts.jvmArtifactId) appendNode("artifactId", SkikoArtifacts.jvmArtifactId)
appendNode("version", skiko.deployVersion) appendNode("version", "[${skiko.deployVersion}]")
appendNode("scope", "compile") appendNode("scope", "compile")
} }
} }
...@@ -183,16 +190,7 @@ private fun SkikoPublishingContext.configureAllJvmRuntimeJarPublications() = pub ...@@ -183,16 +190,7 @@ private fun SkikoPublishingContext.configureAllJvmRuntimeJarPublications() = pub
* which resolves the correct artifact for the current platform. * which resolves the correct artifact for the current platform.
*/ */
private fun SkikoPublishingContext.configureAwtRuntimeJarPublication() { private fun SkikoPublishingContext.configureAwtRuntimeJarPublication() {
/* val allJvmRuntimeVariants = awtRuntimeTargets.map { (os, arch) ->
Defines all the child targets that this uber publication can point to
*/
val childAwtRuntimeTargets = listOf(
OS.MacOS to Arch.X64, OS.MacOS to Arch.Arm64,
OS.Linux to Arch.X64, OS.Linux to Arch.Arm64,
OS.Windows to Arch.X64, OS.Windows to Arch.Arm64
)
val allJvmRuntimeVariants = childAwtRuntimeTargets.map { (os, arch) ->
project.configurations.create("awtRuntimeElements-${targetId(os, arch)}").apply { project.configurations.create("awtRuntimeElements-${targetId(os, arch)}").apply {
/* Setup default attributes */ /* Setup default attributes */
...@@ -259,7 +257,7 @@ private fun SkikoPublishingContext.configureAwtRuntimeJarPublication() { ...@@ -259,7 +257,7 @@ private fun SkikoPublishingContext.configureAwtRuntimeJarPublication() {
from(component) from(component)
pomNameForPublication[name] = "Skiko JVM Runtime" pomNameForPublication[name] = "Skiko JVM Runtime"
groupId = SkikoArtifacts.groupId groupId = SkikoArtifacts.groupId
artifactId = "skiko-awt-runtime" artifactId = SkikoArtifacts.jvmRuntimeArtifactId
version = skiko.deployVersion version = skiko.deployVersion
/* /*
...@@ -278,6 +276,41 @@ private fun SkikoPublishingContext.configureAwtRuntimeJarPublication() { ...@@ -278,6 +276,41 @@ private fun SkikoPublishingContext.configureAwtRuntimeJarPublication() {
} }
} }
/**
* Adds dependency constraints from the skiko-awt (Kotlin) publication to all skiko-awt-runtime-* (JNI) artifacts.
* This ensures compatibility between the Kotlin and native runtime artifacts.
*
* Constraints are added to the awt target's configurations, which automatically propagates them to both:
* - Maven POM (via dependencyManagement section)
* - Gradle Module Metadata (via dependencyConstraints in variants)
*/
private fun SkikoPublishingContext.configureAwtPublicationConstraints() {
// Add constraints to Gradle configurations
// This will automatically generate both POM dependencyManagement and Gradle Module Metadata dependencyConstraints
listOf("awtApiElements", "awtRuntimeElements").forEach { configName ->
project.configurations.findByName(configName)?.let { config ->
// Note: "!!" suffix is used to enforce a strict version
// See https://docs.gradle.org/current/userguide/dependency_versions.html#sec:rich-version-constraints
// Add constraint for the uber runtime artifact
config.dependencyConstraints.add(
project.dependencies.constraints.create(
"${SkikoArtifacts.groupId}:${SkikoArtifacts.jvmRuntimeArtifactId}:${skiko.deployVersion}!!"
)
)
// Add constraints for platform-specific runtime artifacts
awtRuntimeTargets.forEach { (os, arch) ->
config.dependencyConstraints.add(
project.dependencies.constraints.create(
"${SkikoArtifacts.groupId}:${SkikoArtifacts.jvmRuntimeArtifactIdFor(os, arch)}:${skiko.deployVersion}!!"
)
)
}
}
}
}
private fun SkikoPublishingContext.configureAdditionalRuntimeLibrariesPublication() = publications { private fun SkikoPublishingContext.configureAdditionalRuntimeLibrariesPublication() = publications {
additionalRuntimeLibraries.forEach { additionalRuntimeLibraries.forEach {
it.registerMavenPublication(this, emptySourcesJar, pomNameForPublication) it.registerMavenPublication(this, emptySourcesJar, pomNameForPublication)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment