forked from square/okhttp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
298 lines (261 loc) · 8.92 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
@file:Suppress("UnstableApiUsage")
import com.diffplug.gradle.spotless.SpotlessExtension
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import java.net.URI
import kotlinx.validation.ApiValidationExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import ru.vyarus.gradle.plugin.animalsniffer.AnimalSnifferExtension
buildscript {
dependencies {
classpath(libs.gradlePlugin.dokka)
classpath(libs.gradlePlugin.kotlin)
classpath(libs.gradlePlugin.kotlinSerialization)
classpath(libs.gradlePlugin.androidJunit5)
classpath(libs.gradlePlugin.android)
classpath(libs.gradlePlugin.graal)
classpath(libs.gradlePlugin.bnd)
classpath(libs.gradlePlugin.shadow)
classpath(libs.gradlePlugin.animalsniffer)
classpath(libs.gradlePlugin.errorprone)
classpath(libs.gradlePlugin.spotless)
classpath(libs.gradlePlugin.mavenPublish)
classpath(libs.gradlePlugin.binaryCompatibilityValidator)
}
repositories {
mavenCentral()
gradlePluginPortal()
google()
}
}
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
kotlin {
target("**/*.kt")
ktlint()
}
}
allprojects {
group = "com.squareup.okhttp3"
version = "5.0.0-SNAPSHOT"
repositories {
mavenCentral()
google()
}
tasks.create("downloadDependencies") {
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 == "okhttp-bom") return@subprojects
if (project.name == "okhttp-android") return@subprojects
if (project.name == "android-test") return@subprojects
if (project.name == "regression-test") return@subprojects
if (project.name == "android-test-app") return@subprojects
if (project.name == "container-tests") return@subprojects
apply(plugin = "checkstyle")
apply(plugin = "ru.vyarus.animalsniffer")
apply(plugin = "biz.aQute.bnd.builder")
tasks.withType<JavaCompile> {
options.encoding = Charsets.UTF_8.toString()
}
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
tasks.withType<Checkstyle>().configureEach {
exclude("**/CipherSuite.java")
}
val checkstyleConfig: Configuration by configurations.creating
dependencies {
checkstyleConfig(rootProject.libs.checkStyle) {
isTransitive = false
}
}
configure<CheckstyleExtension> {
config = resources.text.fromArchiveEntry(checkstyleConfig, "google_checks.xml")
toolVersion = rootProject.libs.versions.checkStyle.get()
sourceSets = listOf(project.sourceSets["main"])
}
// Animal Sniffer confirms we generally don't use APIs not on Java 8.
configure<AnimalSnifferExtension> {
annotation = "okhttp3.internal.SuppressSignatureCheck"
sourceSets = listOf(project.sourceSets["main"])
}
val signature: Configuration by configurations.getting
dependencies {
// No dependency requirements for testing-support.
if (project.name == "okhttp-testing-support") return@dependencies
if (project.name == "mockwebserver3-junit5") {
// JUnit 5's APIs need java.util.function.Function and java.util.Optional from API 24.
signature(rootProject.libs.signature.android.apilevel24) { artifact { type = "signature" } }
} else {
// Everything else requires Android API 21+.
signature(rootProject.libs.signature.android.apilevel21) { artifact { type = "signature" } }
}
// OkHttp requires Java 8+.
signature(rootProject.libs.codehaus.signature.java18) { artifact { type = "signature" } }
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
freeCompilerArgs = listOf(
"-Xjvm-default=all",
)
}
}
val platform = System.getProperty("okhttp.platform", "jdk9")
val testJavaVersion = System.getProperty("test.java.version", "21").toInt()
val testRuntimeOnly: Configuration by configurations.getting
dependencies {
testRuntimeOnly(rootProject.libs.junit.jupiter.engine)
testRuntimeOnly(rootProject.libs.junit.vintage.engine)
}
tasks.withType<Test> {
useJUnitPlatform()
jvmArgs(
"-Dokhttp.platform=$platform",
)
if (platform == "loom") {
jvmArgs(
"-Djdk.tracePinnedThreads=short",
)
}
val javaToolchains = project.extensions.getByType<JavaToolchainService>()
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(testJavaVersion))
})
maxParallelForks = Runtime.getRuntime().availableProcessors() * 2
testLogging {
exceptionFormat = TestExceptionFormat.FULL
}
systemProperty("okhttp.platform", platform)
systemProperty("junit.jupiter.extensions.autodetection.enabled", "true")
}
// https://publicobject.com/2023/04/16/read-a-project-file-in-a-kotlin-multiplatform-test/
tasks.withType<Test>().configureEach {
environment("OKHTTP_ROOT", rootDir)
}
if (platform == "jdk8alpn") {
// Add alpn-boot on Java 8 so we can use HTTP/2 without a stable API.
val alpnBootVersion = alpnBootVersion()
if (alpnBootVersion != null) {
val alpnBootJar = configurations.detachedConfiguration(
dependencies.create("org.mortbay.jetty.alpn:alpn-boot:$alpnBootVersion")
).singleFile
tasks.withType<Test> {
jvmArgs("-Xbootclasspath/p:${alpnBootJar}")
}
}
} else if (platform == "conscrypt") {
dependencies {
testRuntimeOnly(rootProject.libs.conscrypt.openjdk)
}
} else if (platform == "openjsse") {
dependencies {
testRuntimeOnly(rootProject.libs.openjsse)
}
}
tasks.withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
}
}
// Opt-in to @ExperimentalOkHttpApi everywhere.
subprojects {
plugins.withId("org.jetbrains.kotlin.jvm") {
kotlinExtension.sourceSets.configureEach {
languageSettings.optIn("okhttp3.ExperimentalOkHttpApi")
}
}
plugins.withId("org.jetbrains.kotlin.android") {
kotlinExtension.sourceSets.configureEach {
languageSettings.optIn("okhttp3.ExperimentalOkHttpApi")
}
}
}
/** Configure publishing and signing for published Java and JavaPlatform subprojects. */
subprojects {
tasks.withType<DokkaTaskPartial>().configureEach {
dokkaSourceSets.configureEach {
reportUndocumented.set(false)
skipDeprecated.set(true)
jdkVersion.set(8)
perPackageOption {
matchingRegex.set(".*\\.internal.*")
suppress.set(true)
}
if (project.file("Module.md").exists()) {
includes.from(project.file("Module.md"))
}
externalDocumentationLink {
url.set(URI.create("https://square.github.io/okio/3.x/okio/").toURL())
packageListUrl.set(URI.create("https://square.github.io/okio/3.x/okio/okio/package-list").toURL())
}
}
}
plugins.withId("com.vanniktech.maven.publish.base") {
val publishingExtension = extensions.getByType(PublishingExtension::class.java)
configure<MavenPublishBaseExtension> {
publishToMavenCentral(SonatypeHost.S01, automaticRelease = true)
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")
}
}
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")
}
developers {
developer {
name.set("Square, Inc.")
}
}
}
}
}
plugins.withId("binary-compatibility-validator") {
configure<ApiValidationExtension> {
ignoredPackages += "okhttp3.logging.internal"
ignoredPackages += "mockwebserver3.internal"
ignoredPackages += "okhttp3.internal"
ignoredPackages += "mockwebserver3.junit5.internal"
ignoredPackages += "okhttp3.brotli.internal"
ignoredPackages += "okhttp3.sse.internal"
ignoredPackages += "okhttp3.tls.internal"
}
}
}
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}