forked from square/okhttp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
307 lines (272 loc) · 9.71 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
299
300
301
302
303
304
305
306
307
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
import org.jetbrains.dokka.gradle.DokkaTask
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.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")
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
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(11))
}
}
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", "11").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 = jvmArgs!! + listOf(
"-Dokhttp.platform=$platform",
"-XX:+HeapDumpOnOutOfMemoryError"
)
if (platform == "loom") {
jvmArgs = jvmArgs!! + listOf(
"-Djdk.tracePinnedThread=full",
"--enable-preview"
)
}
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")
}
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 = jvmArgs!! + listOf("-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()
}
}
/** 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 {
matchingRegex.set("okhttp3\\.internal.*")
suppress.set(true)
}
perPackageOption {
matchingRegex.set("mockwebserver3\\.internal.*")
suppress.set(true)
}
if (project.file("Module.md").exists()) {
includes.from(project.file("Module.md"))
}
externalDocumentationLink {
url.set(URL("https://square.github.io/okio/2.x/okio/"))
packageListUrl.set(URL("https://square.github.io/okio/2.x/okio/package-list"))
}
}
if (name == "dokkaGfm") {
outputDirectory.set(file("${rootDir}/docs/4.x"))
}
}
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://[email protected]/square/okhttp.git")
url.set("https://github.com/square/okhttp")
}
developers {
developer {
name.set("Square, Inc.")
}
}
}
// 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")
}
}
}
}
}
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"
}
}
plugins.withId("org.jetbrains.kotlin.jvm") {
val jvmTest by tasks.creating {
description = "Get 'gradlew jvmTest' to run the tests of JVM-only modules"
dependsOn("test")
}
}
}
tasks.wrapper {
distributionType = Wrapper.DistributionType.ALL
}