Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pom.xml depend on the JVM artifact #7354

Merged
merged 1 commit into from Jun 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions build.gradle.kts
@@ -1,5 +1,7 @@
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import groovy.util.Node
import groovy.util.NodeList
import java.net.URL
import kotlinx.validation.ApiValidationExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
Expand Down Expand Up @@ -209,6 +211,7 @@ subprojects {
}

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

// Configure the kotlinMultiplatform artifact to depend on the JVM artifact in pom.xml only.
// This hack allows Maven users to continue using our original OkHttp artifact names (like
// com.squareup.okhttp3:okhttp:5.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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think I want this line. Shouldn’t the scope be compile + runtime?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking compileOnly, not compile. This is fine.

}
}
}
}
}

Expand Down