1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-12 10:23:16 +03:00

Convert the main build.gradle file to KTS (#6925)

I attempted to do a literal translation as much as possible.
Subprojects now need plugins to be configured directly so they
can use the appropriate syntax.
This commit is contained in:
Jesse Wilson
2021-11-24 02:19:39 -05:00
committed by GitHub
parent 7d9ea7de2c
commit 35bb1740a4
23 changed files with 350 additions and 260 deletions

View File

@@ -1,258 +0,0 @@
buildscript {
dependencies {
classpath Dependencies.kotlinPlugin
classpath Dependencies.dokkaPlugin
classpath Dependencies.androidPlugin
classpath Dependencies.androidJunit5Plugin
classpath Dependencies.graalPlugin
classpath Dependencies.bndPlugin
classpath Dependencies.shadowPlugin
classpath Dependencies.japicmpPlugin
classpath Dependencies.animalsnifferPlugin
classpath Dependencies.errorpronePlugin
classpath Dependencies.spotlessPlugin
}
repositories {
mavenCentral()
gradlePluginPortal()
google()
}
}
allprojects {
group = 'com.squareup.okhttp3'
project.ext.artifactId = Projects.publishedArtifactId(project.name)
version = '5.0.0-SNAPSHOT'
repositories {
mavenCentral()
google()
maven { url 'https://dl.bintray.com/kotlin/dokka' }
}
task downloadDependencies() {
description 'Download all dependencies to the Gradle cache'
doLast {
configurations.findAll { it.canBeResolved }.files
}
}
normalization {
runtimeClasspath {
metaInf {
ignoreAttribute("Bnd-LastModified")
}
}
}
}
/** Configure building for Java+Kotlin projects. */
subprojects { project ->
if (project.name == 'android-test') return
if (project.name == 'okhttp-bom') return
if (project.name == 'regression-test') return
apply plugin: "org.jetbrains.kotlin.jvm"
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'checkstyle'
apply plugin: "com.diffplug.spotless"
apply plugin: 'ru.vyarus.animalsniffer'
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'biz.aQute.bnd.builder'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
vendor = JvmVendorSpec.ADOPTOPENJDK
}
}
checkstyleMain.exclude '**/CipherSuite.java'
configurations {
checkstyleConfig
}
dependencies {
checkstyleConfig dependencies.create(Dependencies.checkStyle) {
transitive = false
}
}
afterEvaluate {
checkstyle {
config = resources.text.fromArchiveEntry(configurations.checkstyleConfig, 'google_checks.xml')
toolVersion "${Versions.checkStyle}"
sourceSets = [project.sourceSets.main]
}
}
// Animal Sniffer confirms we generally don't use APIs not on Java 8.
animalsniffer {
annotation "okhttp3.internal.SuppressSignatureCheck"
sourceSets = [sourceSets.main]
}
dependencies {
signature Dependencies.signatureAndroid21
signature Dependencies.signatureJava18
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = ['-Xjvm-default=compatibility', '-Xopt-in=kotlin.RequiresOptIn']
}
}
def platform = System.getProperty("okhttp.platform", "jdk9")
def testJavaVersion = Integer.getInteger("test.java.version", 11)
dependencies {
testRuntimeOnly(Dependencies.junit5JupiterEngine)
testRuntimeOnly(Dependencies.junit5VintageEngine)
}
test {
useJUnitPlatform()
jvmArgs += "-Dokhttp.platform=$platform"
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(testJavaVersion)
vendor = JvmVendorSpec.ADOPTOPENJDK
}
maxParallelForks Runtime.runtime.availableProcessors() * 2
testLogging {
exceptionFormat = 'full'
}
systemProperty 'okhttp.platform', platform
systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'
}
if (platform == "jdk8alpn") {
// Add alpn-boot on Java 8 so we can use HTTP/2 without a stable API.
def alpnBootVersion = Alpn.alpnBootVersion()
if (alpnBootVersion != null) {
def alpnBootJar = configurations.detachedConfiguration(
dependencies.create("org.mortbay.jetty.alpn:alpn-boot:$alpnBootVersion")).singleFile
test {
jvmArgs += "-Xbootclasspath/p:${alpnBootJar}"
}
}
} else if (platform == "conscrypt") {
dependencies {
testRuntimeOnly Dependencies.conscrypt
}
} else if (platform == "openjsse") {
dependencies {
testRuntimeOnly Dependencies.openjsse
}
}
tasks.withType(JavaCompile).configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
dokka {
configuration {
reportUndocumented = false
skipDeprecated = true
jdkVersion = 8
perPackageOption {
prefix = "okhttp3.internal"
suppress = true
}
perPackageOption {
prefix = "mockwebserver3.internal"
suppress = true
}
if (project.file('Module.md').exists()) {
includes = ['Module.md']
}
externalDocumentationLink {
url = new URL("https://square.github.io/okio/2.x/okio/")
packageListUrl = new URL("https://square.github.io/okio/2.x/okio/package-list")
}
}
}
}
/** Configure publishing and signing for published Java and JavaPlatform subprojects. */
subprojects { project ->
if (project.ext.artifactId == null) return
def bom = project.ext.artifactId == 'okhttp-bom'
if (bom) {
apply plugin: 'java-platform'
}
apply plugin: 'maven-publish'
apply plugin: 'signing'
publishing {
if (!bom) {
java {
withJavadocJar()
withSourcesJar()
}
}
publications {
maven(MavenPublication) {
groupId = project.group
artifactId = project.ext.artifactId
version = project.version
if (bom) {
from components.javaPlatform
} else {
from components.java
}
pom {
name = project.name
description = 'Squares meticulous HTTP client for Java and Kotlin.'
url = 'https://square.github.io/okhttp/'
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
name = 'Square, Inc.'
}
}
scm {
connection = 'scm:git:https://github.com/square/okhttp.git'
developerConnection = 'scm:git:ssh://git@github.com/square/okhttp.git'
url = 'https://github.com/square/okhttp'
}
}
}
}
repositories {
maven {
name = "mavencentral"
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username System.getenv('SONATYPE_NEXUS_USERNAME')
password System.getenv('SONATYPE_NEXUS_PASSWORD')
}
}
}
}
signing {
sign publishing.publications.maven
}
}
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}

279
build.gradle.kts Normal file
View File

@@ -0,0 +1,279 @@
import java.net.URI
import java.net.URL
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension
buildscript {
dependencies {
classpath(Dependencies.kotlinPlugin)
classpath(Dependencies.dokkaPlugin)
classpath(Dependencies.androidPlugin)
classpath(Dependencies.androidJunit5Plugin)
classpath(Dependencies.graalPlugin)
classpath(Dependencies.bndPlugin)
classpath(Dependencies.shadowPlugin)
classpath(Dependencies.japicmpPlugin)
classpath(Dependencies.animalsnifferPlugin)
classpath(Dependencies.errorpronePlugin)
classpath(Dependencies.spotlessPlugin)
}
repositories {
mavenCentral()
gradlePluginPortal()
google()
}
}
allprojects {
group = "com.squareup.okhttp3"
project.ext["artifactId"] = Projects.publishedArtifactId(project.name)
version = "5.0.0-SNAPSHOT"
repositories {
mavenCentral()
google()
maven(url = "https://dl.bintray.com/kotlin/dokka")
}
val downloadDependencies by tasks.creating {
description = "Download all dependencies to the Gradle cache"
doLast {
for (configuration in configurations) {
if (configuration.isCanBeResolved) {
configuration.files
}
}
}
}
normalization {
runtimeClasspath {
metaInf {
ignoreAttribute("Bnd-LastModified")
}
}
}
}
/** Configure building for Java+Kotlin projects. */
subprojects {
val project = this@subprojects
if (project.name == "android-test") return@subprojects
if (project.name == "okhttp-bom") return@subprojects
if (project.name == "regression-test") return@subprojects
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "checkstyle")
apply(plugin = "com.diffplug.spotless")
apply(plugin = "ru.vyarus.animalsniffer")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "biz.aQute.bnd.builder")
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
vendor.set(JvmVendorSpec.ADOPTOPENJDK)
}
}
tasks.withType<Checkstyle>().configureEach {
exclude("**/CipherSuite.java")
}
val checkstyleConfig by configurations.creating
dependencies {
checkstyleConfig(Dependencies.checkStyle) {
isTransitive = false
}
}
afterEvaluate {
configure<CheckstyleExtension> {
config = resources.text.fromArchiveEntry(checkstyleConfig, "google_checks.xml")
toolVersion = Versions.checkStyle
sourceSets = listOf(project.sourceSets.getByName("main"))
}
}
// Animal Sniffer confirms we generally don't use APIs not on Java 8.
configure<AnimalSnifferExtension> {
annotation = "okhttp3.internal.SuppressSignatureCheck"
sourceSets = listOf(project.sourceSets.getByName("main"))
}
val signature by configurations.getting
dependencies {
signature(Dependencies.signatureAndroid21)
signature(Dependencies.signatureJava18)
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf(
"-Xjvm-default=compatibility",
"-Xopt-in=kotlin.RequiresOptIn"
)
}
}
val platform = System.getProperty("okhttp.platform", "jdk9")
val testJavaVersion = System.getProperty("test.java.version", "11").toInt()
val testRuntimeOnly by configurations.getting
dependencies {
testRuntimeOnly(Dependencies.junit5JupiterEngine)
testRuntimeOnly(Dependencies.junit5VintageEngine)
}
tasks.withType<Test> {
useJUnitPlatform()
jvmArgs = jvmArgs!! + listOf("-Dokhttp.platform=$platform")
val javaToolchains = project.extensions.getByType<JavaToolchainService>()
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(testJavaVersion))
vendor.set(JvmVendorSpec.ADOPTOPENJDK)
})
maxParallelForks = Runtime.getRuntime().availableProcessors() * 2
testLogging {
exceptionFormat = TestExceptionFormat.FULL
}
systemProperty("okhttp.platform", platform)
systemProperty("junit.jupiter.extensions.autodetection.enabled", "true")
}
if (platform == "jdk8alpn") {
// Add alpn-boot on Java 8 so we can use HTTP/2 without a stable API.
val alpnBootVersion = Alpn.alpnBootVersion()
if (alpnBootVersion != null) {
val alpnBootJar = configurations.detachedConfiguration(
dependencies.create("org.mortbay.jetty.alpn:alpn-boot:$alpnBootVersion")
).singleFile
tasks.withType<Test> {
jvmArgs = jvmArgs!! + listOf("-Xbootclasspath/p:${alpnBootJar}")
}
}
} else if (platform == "conscrypt") {
dependencies {
testRuntimeOnly(Dependencies.conscrypt)
}
} else if (platform == "openjsse") {
dependencies {
testRuntimeOnly(Dependencies.openjsse)
}
}
tasks.withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
}
tasks.withType<DokkaTask> {
configuration {
reportUndocumented = false
skipDeprecated = true
jdkVersion = 8
perPackageOption {
prefix = "okhttp3.internal"
suppress = true
}
perPackageOption {
prefix = "mockwebserver3.internal"
suppress = true
}
if (project.file("Module.md").exists()) {
includes = listOf("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")
}
}
}
}
/** 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 {
val maven by creating(MavenPublication::class) {
groupId = project.group.toString()
artifactId = project.ext["artifactId"].toString()
version = project.version.toString()
if (bom) {
from(components.getByName("javaPlatform"))
} else {
from(components.getByName("java"))
}
pom {
name.set(project.name)
description.set("Squares 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("http://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://git@github.com/square/okhttp.git")
url.set("https://github.com/square/okhttp")
}
}
}
}
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")
}
}
}
}
val publishing = extensions.getByType<PublishingExtension>()
configure<SigningExtension> {
sign(publishing.publications.getByName("maven"))
}
}
tasks.withType<Wrapper> {
distributionType = Wrapper.DistributionType.ALL
}

View File

@@ -2,7 +2,9 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn
import me.champeau.gradle.japicmp.JapicmpTask
plugins {
kotlin("jvm")
id("me.champeau.gradle.japicmp")
id("org.jetbrains.dokka")
}
tasks.jar {

View File

@@ -1,3 +1,8 @@
plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
}
tasks.jar {
manifest {
attributes("Automatic-Module-Name" to "mockwebserver3.junit4")

View File

@@ -1,3 +1,8 @@
plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
}
tasks {
jar {
manifest {

View File

@@ -1,3 +1,7 @@
plugins {
kotlin("jvm")
}
tasks.jar {
manifest {
attributes("Automatic-Module-Name" to "mockwebserver3")

View File

@@ -3,6 +3,7 @@ import java.nio.charset.StandardCharsets
import org.apache.tools.ant.taskdefs.condition.Os
plugins {
kotlin("jvm")
kotlin("kapt")
id("com.palantir.graal")
id("com.github.johnrengelman.shadow")
@@ -29,7 +30,7 @@ tasks.register<Copy>("copyResourcesTemplates") {
filteringCharset = StandardCharsets.UTF_8.toString()
}.let {
tasks.processResources.dependsOn(it)
tasks.sourcesJar.dependsOn(it)
tasks.named("sourcesJar").dependsOn(it)
}
dependencies {

View File

@@ -1,3 +1,7 @@
plugins {
id("java-platform")
}
dependencies {
constraints {
project.rootProject.subprojects.forEach { subproject ->

View File

@@ -1,3 +1,8 @@
plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
}
Projects.applyOsgi(
project,
"Export-Package: okhttp3.brotli",

View File

@@ -1,3 +1,8 @@
plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
}
Projects.applyOsgi(
project,
"Export-Package: okhttp3.dnsoverhttps",

View File

@@ -1,3 +1,7 @@
plugins {
kotlin("jvm")
}
dependencies {
testImplementation(Dependencies.okio)
testImplementation(Dependencies.moshi)

View File

@@ -2,6 +2,8 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn
import me.champeau.gradle.japicmp.JapicmpTask
plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
id("me.champeau.gradle.japicmp")
}

View File

@@ -2,6 +2,8 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn
import me.champeau.gradle.japicmp.JapicmpTask
plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
id("me.champeau.gradle.japicmp")
}

View File

@@ -1,3 +1,8 @@
plugins {
kotlin("jvm")
id("ru.vyarus.animalsniffer")
}
dependencies {
api(project(":okhttp"))
api(Dependencies.assertj)

View File

@@ -2,6 +2,9 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn
import me.champeau.gradle.japicmp.JapicmpTask
plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
id("ru.vyarus.animalsniffer")
id("me.champeau.gradle.japicmp")
}

View File

@@ -2,6 +2,8 @@ import com.android.build.gradle.internal.tasks.factory.dependsOn
import me.champeau.gradle.japicmp.JapicmpTask
plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
id("me.champeau.gradle.japicmp")
}

View File

@@ -3,7 +3,9 @@ import java.nio.charset.StandardCharsets
import me.champeau.gradle.japicmp.JapicmpTask
plugins {
kotlin("jvm")
id("me.champeau.gradle.japicmp")
id("org.jetbrains.dokka")
}
Projects.applyOsgi(
@@ -62,7 +64,7 @@ tasks.register<Copy>("copyJavaTemplates") {
filteringCharset = StandardCharsets.UTF_8.toString()
}.let {
tasks.compileKotlin.dependsOn(it)
tasks.sourcesJar.dependsOn(it)
tasks.named("sourcesJar").dependsOn(it)
}
// Expose OSGi jars to the test environment.

View File

@@ -1,3 +1,7 @@
plugins {
kotlin("jvm")
}
dependencies {
testImplementation(project(":okhttp"))
testImplementation(project(":mockwebserver"))

View File

@@ -1,4 +1,5 @@
plugins {
kotlin("jvm")
kotlin("kapt")
}

View File

@@ -1,3 +1,7 @@
plugins {
kotlin("jvm")
}
dependencies {
implementation(project(":okhttp"))
implementation(Dependencies.moshi)

View File

@@ -1,3 +1,7 @@
plugins {
kotlin("jvm")
}
dependencies {
implementation(project(":mockwebserver-deprecated"))
implementation(Dependencies.moshi)

View File

@@ -1,4 +1,5 @@
plugins {
kotlin("jvm")
id("com.github.johnrengelman.shadow")
}

View File

@@ -1,3 +1,7 @@
plugins {
kotlin("jvm")
}
dependencies {
implementation(project(":okhttp"))
implementation(project(":mockwebserver-deprecated"))