Skip to content

Commit

Permalink
Make pom.xml depend on the JVM artifact (#1125)
Browse files Browse the repository at this point in the history
This should prevent Maven users from needing to change
their dependencies from okio to okio-jvm. More importantly,
it should also prevent them from inadvertently getting two
different Okio JVM artifacts on their classpaths at once.
  • Loading branch information
squarejesse authored Jun 27, 2022
1 parent ba4eec2 commit 73c08ca
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import aQute.bnd.gradle.BundleTaskConvention
import com.diffplug.gradle.spotless.SpotlessExtension
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import groovy.util.Node
import groovy.util.NodeList
import java.nio.charset.StandardCharsets
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
Expand Down Expand Up @@ -87,6 +89,7 @@ allprojects {
}

plugins.withId("com.vanniktech.maven.publish.base") {
val publishingExtension = extensions.getByType(PublishingExtension::class.java)
configure<MavenPublishBaseExtension> {
publishToMavenCentral(SonatypeHost.S01)
signAllPublications()
Expand All @@ -113,6 +116,31 @@ allprojects {
}
}
}

// Configure the kotlinMultiplatform artifact to depend on the JVM artifact in pom.xml only.
// This hack allows Maven users to continue using our original Okio artifact names (like
// com.squareup.okio:okio:3.x.y) even though we changed that artifact from JVM-only to Kotlin
// Multiplatform. Note that module.json doesn't need this hack.
val mavenPublications = publishingExtension.publications.withType<MavenPublication>()
mavenPublications.configureEach {
if (name != "jvm") return@configureEach
val jvmPublication = this
val kmpPublication = mavenPublications.getByName("kotlinMultiplatform")
kmpPublication.pom.withXml {
val root = asNode()
val dependencies = (root["dependencies"] as NodeList).firstOrNull() as Node?
?: root.appendNode("dependencies")
for (child in dependencies.children().toList()) {
dependencies.remove(child as Node)
}
dependencies.appendNode("dependency").apply {
appendNode("groupId", jvmPublication.groupId)
appendNode("artifactId", jvmPublication.artifactId)
appendNode("version", jvmPublication.version)
appendNode("scope", "compile")
}
}
}
}
}
}
Expand Down

0 comments on commit 73c08ca

Please sign in to comment.