Skip to content

Commit

Permalink
Switch to Vanniktech for Maven publishing (square#6929)
Browse files Browse the repository at this point in the history
* Switch to Vanniktech for Maven publishing

Steal configuration from Okio, which already works nicely.

* Update mockwebserver-junit5/build.gradle.kts

Co-authored-by: Benoît Quenaudon <[email protected]>

Co-authored-by: Benoît Quenaudon <[email protected]>
  • Loading branch information
swankjesse and oldergod committed Nov 26, 2021
1 parent d0759a7 commit d9a65a8
Show file tree
Hide file tree
Showing 25 changed files with 206 additions and 224 deletions.
2 changes: 1 addition & 1 deletion android-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencies {
androidTestImplementation(Dependencies.bouncycastle)
androidTestImplementation(Dependencies.bouncycastletls)
androidTestImplementation(Dependencies.conscryptAndroid)
androidTestImplementation(project(":mockwebserver-junit5"))
androidTestImplementation(project(":mockwebserver3-junit5"))
androidTestImplementation(project(":okhttp-brotli"))
androidTestImplementation(project(":okhttp-dnsoverhttps"))
androidTestImplementation(project(":okhttp-logging-interceptor"))
Expand Down
122 changes: 42 additions & 80 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import java.net.URI
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import java.net.URL
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.dokka.gradle.DokkaTask
Expand All @@ -18,6 +19,7 @@ buildscript {
classpath(Dependencies.animalsnifferPlugin)
classpath(Dependencies.errorpronePlugin)
classpath(Dependencies.spotlessPlugin)
classpath(Dependencies.vanniktechPublishPlugin)
}

repositories {
Expand All @@ -27,9 +29,10 @@ buildscript {
}
}

apply(plugin = "com.vanniktech.maven.publish.base")

allprojects {
group = "com.squareup.okhttp3"
project.ext["artifactId"] = project.name.publishedArtifactId()
version = "5.0.0-SNAPSHOT"

repositories {
Expand Down Expand Up @@ -176,102 +179,61 @@ subprojects {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
}
}

tasks.withType<DokkaTask> {
configuration {
reportUndocumented = false
skipDeprecated = true
jdkVersion = 8
/** Configure publishing and signing for published Java and JavaPlatform subprojects. */
subprojects {
tasks.withType<DokkaTask>().configureEach {
dokkaSourceSets.configureEach {
reportUndocumented.set(false)
skipDeprecated.set(true)
jdkVersion.set(8)
perPackageOption {
prefix = "okhttp3.internal"
suppress = true
matchingRegex.set("okhttp3\\.internal.*")
suppress.set(true)
}
perPackageOption {
prefix = "mockwebserver3.internal"
suppress = true
matchingRegex.set("mockwebserver3\\.internal.*")
suppress.set(true)
}
if (project.file("Module.md").exists()) {
includes = listOf("Module.md")
includes.from(project.file("Module.md"))
}
externalDocumentationLink {
url = URL("https://square.github.io/okio/2.x/okio/")
packageListUrl = URL("https://square.github.io/okio/2.x/okio/package-list")
url.set(URL("https://square.github.io/okio/2.x/okio/"))
packageListUrl.set(URL("https://square.github.io/okio/2.x/okio/package-list"))
}
}
}
}

/** Configure publishing and signing for published Java and JavaPlatform subprojects. */
subprojects {
val project = this@subprojects
if (project.ext.get("artifactId") == null) return@subprojects
val bom = project.ext["artifactId"] == "okhttp-bom"

if (bom) {
apply(plugin = "java-platform")
}

apply(plugin = "maven-publish")
apply(plugin = "signing")

configure<PublishingExtension> {
if (!bom) {
configure<JavaPluginExtension> {
withJavadocJar()
withSourcesJar()
}
}

publications {
create<MavenPublication>("maven") {
groupId = project.group.toString()
artifactId = project.ext["artifactId"].toString()
version = project.version.toString()
if (bom) {
from(components["javaPlatform"])
} else {
from(components["java"])
}
pom {
name.set(project.name)
description.set("Square’s meticulous HTTP client for Java and Kotlin.")
url.set("https://square.github.io/okhttp/")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
name.set("Square, Inc.")
}
}
scm {
connection.set("scm:git:https://github.com/square/okhttp.git")
developerConnection.set("scm:git:ssh:https://[email protected]/square/okhttp.git")
url.set("https://github.com/square/okhttp")
plugins.withId("com.vanniktech.maven.publish.base") {
configure<MavenPublishBaseExtension> {
publishToMavenCentral(SonatypeHost.DEFAULT)
signAllPublications()
pom {
name.set(project.name)
description.set("Square’s meticulous HTTP client for Java and Kotlin.")
url.set("https://square.github.io/okhttp/")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
}
}

repositories {
maven {
name = "mavencentral"
url = URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = System.getenv("SONATYPE_NEXUS_USERNAME")
password = System.getenv("SONATYPE_NEXUS_PASSWORD")
scm {
connection.set("scm:git:https://github.com/square/okhttp.git")
developerConnection.set("scm:git:ssh:https://[email protected]/square/okhttp.git")
url.set("https://github.com/square/okhttp")
}
developers {
developer {
name.set("Square, Inc.")
}
}
}
}
}

val publishing = extensions.getByType<PublishingExtension>()
configure<SigningExtension> {
sign(publishing.publications["maven"])
}
}

tasks.withType<Wrapper> {
Expand Down
25 changes: 2 additions & 23 deletions buildSrc/src/main/kotlin/artifacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,9 @@ import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.extra
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.withConvention

fun String.publishedArtifactId(): String? {
return when (this) {
"okhttp-logging-interceptor" -> "logging-interceptor"
"mockwebserver" -> "mockwebserver3"
"mockwebserver-junit4" -> "mockwebserver3-junit4"
"mockwebserver-junit5" -> "mockwebserver3-junit5"
"mockwebserver-deprecated" -> "mockwebserver"
"okcurl",
"okhttp",
"okhttp-bom",
"okhttp-brotli",
"okhttp-dnsoverhttps",
"okhttp-sse",
"okhttp-tls",
"okhttp-urlconnection" -> this
else -> null
}
}

fun Project.applyOsgi(vararg bndProperties: String) {
apply(plugin = "biz.aQute.bnd.builder")
sourceSets.create("osgi")
Expand All @@ -59,11 +39,10 @@ fun Project.applyOsgi(vararg bndProperties: String) {
*/
fun Project.baselineJar(version: String = "3.14.1"): File? {
val originalGroup = group
val artifactId = extra["artifactId"]
return try {
val jarFile = "$artifactId-${version}.jar"
val jarFile = "$name-$version.jar"
group = "virtual_group_for_japicmp"
val dependency = dependencies.create("$originalGroup:$artifactId:$version@jar")
val dependency = dependencies.create("$originalGroup:$name:$version@jar")
configurations.detachedConfiguration(dependency).files.find { (it.name == jarFile) }
} catch (e: Exception) {
null
Expand Down
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object Versions {

object Dependencies {
const val kotlinPlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
const val dokkaPlugin = "org.jetbrains.dokka:dokka-gradle-plugin:0.10.1"
const val dokkaPlugin = "org.jetbrains.dokka:dokka-gradle-plugin:1.5.31"
const val androidPlugin = "com.android.tools.build:gradle:7.0.2"
const val androidJunit5Plugin = "de.mannodermaus.gradle.plugins:android-junit5:1.8.0.0"
const val graalPlugin = "gradle.plugin.com.palantir.graal:gradle-graal:0.9.0"
Expand All @@ -39,6 +39,7 @@ object Dependencies {
const val animalsnifferPlugin = "ru.vyarus:gradle-animalsniffer-plugin:1.5.3"
const val errorpronePlugin = "net.ltgt.gradle:gradle-errorprone-plugin:2.0.2"
const val spotlessPlugin = "com.diffplug.spotless:spotless-plugin-gradle:5.15.0"
const val vanniktechPublishPlugin = "com.vanniktech:gradle-maven-publish-plugin:0.18.0"

const val android = "org.robolectric:android-all:12-robolectric-7732740"
const val animalSniffer = "org.codehaus.mojo:animal-sniffer-annotations:1.20"
Expand Down
20 changes: 11 additions & 9 deletions mockwebserver-deprecated/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import com.android.build.gradle.internal.tasks.factory.dependsOn
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import me.champeau.gradle.japicmp.JapicmpTask

plugins {
kotlin("jvm")
id("me.champeau.gradle.japicmp")
id("org.jetbrains.dokka")
id("com.vanniktech.maven.publish.base")
id("me.champeau.gradle.japicmp")
}

tasks.jar {
Expand All @@ -15,21 +19,14 @@ tasks.jar {

dependencies {
api(project(":okhttp"))
api(project(":mockwebserver"))
api(project(":mockwebserver3"))
api(Dependencies.junit)

testImplementation(project(":okhttp-testing-support"))
testImplementation(project(":okhttp-tls"))
testImplementation(Dependencies.assertj)
}

afterEvaluate {
tasks.dokka {
outputDirectory = "$rootDir/docs/4.x"
outputFormat = "gfm"
}
}

tasks.register<JapicmpTask>("japicmp") {
dependsOn("jar")
oldClasspath = files(project.baselineJar())
Expand All @@ -49,3 +46,8 @@ tasks.register<JapicmpTask>("japicmp") {
"okhttp3.mockwebserver.QueueDispatcher"
)
}.let(tasks.check::dependsOn)


configure<MavenPublishBaseExtension> {
configure(KotlinJvm(javadocJar = JavadocJar.Dokka("dokkaGfm")))
}
14 changes: 8 additions & 6 deletions mockwebserver-junit4/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.MavenPublishBaseExtension

plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
id("com.vanniktech.maven.publish.base")
}

tasks.jar {
Expand All @@ -10,15 +15,12 @@ tasks.jar {
}

dependencies {
api(project(":mockwebserver"))
api(project(":mockwebserver3"))
api(Dependencies.junit)

testImplementation(Dependencies.assertj)
}

afterEvaluate {
tasks.dokka {
outputDirectory = "$rootDir/docs/4.x"
outputFormat = "gfm"
}
configure<MavenPublishBaseExtension> {
configure(KotlinJvm(javadocJar = JavadocJar.Dokka("dokkaGfm")))
}
14 changes: 8 additions & 6 deletions mockwebserver-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.MavenPublishBaseExtension

plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
id("com.vanniktech.maven.publish.base")
}

tasks {
Expand All @@ -16,7 +21,7 @@ tasks {
}

dependencies {
api(project(":mockwebserver"))
api(project(":mockwebserver3"))
api(Dependencies.junit5Api)
compileOnly(Dependencies.animalSniffer)

Expand All @@ -25,9 +30,6 @@ dependencies {
testImplementation(Dependencies.kotlinJunit5)
}

afterEvaluate {
tasks.dokka {
outputDirectory = "$rootDir/docs/4.x"
outputFormat = "gfm"
}
configure<MavenPublishBaseExtension> {
configure(KotlinJvm(javadocJar = JavadocJar.Dokka("dokkaGfm")))
}
15 changes: 9 additions & 6 deletions mockwebserver/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.MavenPublishBaseExtension

plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
id("com.vanniktech.maven.publish.base")
}

tasks.jar {
Expand All @@ -13,14 +19,11 @@ dependencies {

testImplementation(project(":okhttp-testing-support"))
testImplementation(project(":okhttp-tls"))
testRuntimeOnly(project(":mockwebserver-junit5"))
testRuntimeOnly(project(":mockwebserver3-junit5"))
testImplementation(Dependencies.junit)
testImplementation(Dependencies.assertj)
}

afterEvaluate {
tasks.dokka {
outputDirectory = "$rootDir/docs/4.x"
outputFormat = "gfm"
}
configure<MavenPublishBaseExtension> {
configure(KotlinJvm(javadocJar = JavadocJar.Dokka("dokkaGfm")))
}
6 changes: 3 additions & 3 deletions native-image-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ dependencies {
implementation(project(":okhttp-testing-support"))
implementation(project(":okhttp-tls"))
implementation(Dependencies.assertj)
implementation(project(":mockwebserver3"))
implementation(project(":mockwebserver"))
implementation(project(":mockwebserver-deprecated"))
implementation(project(":okhttp-urlconnection"))
implementation(project(":mockwebserver-junit4"))
implementation(project(":mockwebserver-junit5"))
implementation(project(":mockwebserver3-junit4"))
implementation(project(":mockwebserver3-junit5"))
implementation(Dependencies.bndResolve)
implementation(Dependencies.junit5Api)
implementation(Dependencies.junit5JupiterParams)
Expand Down
Loading

0 comments on commit d9a65a8

Please sign in to comment.