okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

Artifact coordinates changed in 5.x releases for Maven users

Open robertvazan opened this issue 2 years ago • 4 comments

Could you provide guidance on how to deal with okhttp-jvm/okhttp JAR mixup? Given app A and library L, both upgrade paths are perilous:

App first: A -> L + okhttp-jvm:5, L -> okhttp:4 Library first: A -> L + okhttp:4, L -> okhttp-jvm:5

Both cases get resolved by maven to A -> okhttp:4 + okhttp-jvm:5, which will result in class loading conflicts at runtime.

From library point of view, no matter which version of okhttp is chosen, some dependent apps will end up with broken build. It looks like the only solution is to bundle okhttp under library's package tree. Or am I missing something?

robertvazan avatar Jun 17 '22 16:06 robertvazan

Yeah sorry about this. We're using gradle everywhere which papers over this problem. Will look into building a better story for Maven users.

swankjesse avatar Jun 17 '22 16:06 swankjesse

Is this the fix? https://kotlinlang.slack.com/archives/C3PQML5NU/p1655635540306199

publishing {
    publications {
        val jvm = getByName<MavenPublication>("jvm")
        getByName<MavenPublication>("kotlinMultiplatform") {
            pom.withXml {
                val root = asNode()
                val dependencies = ((root["dependencies"] as NodeList).firstOrNull() as Node?)?.apply {
                    for (child in children().toList()) remove(child as Node)
                } ?: root.appendNode("dependencies")
                dependencies.appendNode("dependency").apply {
                    appendNode("groupId", jvm.groupId)
                    appendNode("artifactId", jvm.artifactId)
                    appendNode("version", jvm.version)
                    appendNode("scope", "compile")
                }
            }
        }
    }
}

yschimke avatar Jun 19 '22 17:06 yschimke

That would depend on what the type and contents of the binary for the multiplatform artifact was. Seems like a better option would be to change the suffixes to have the JVM artifact the unqualified one with the Gradle module metadata.

JakeWharton avatar Jun 20 '22 13:06 JakeWharton

I’m gonna try doing this on both OkHttp and Okio https://github.com/square/okhttp/pull/7354 https://github.com/square/okio/pull/1125

swankjesse avatar Jun 26 '22 18:06 swankjesse