-
Notifications
You must be signed in to change notification settings - Fork 289
/
build.gradle.kts
162 lines (150 loc) · 5.58 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
/*
* Copyright (C) 2019 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.diffplug.gradle.spotless.SpotlessExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.dokka) apply false
alias(libs.plugins.spotless) apply false
alias(libs.plugins.mavenPublish) apply false
alias(libs.plugins.kotlinBinaryCompatibilityValidator)
}
allprojects {
// Note that the group name for publishing is "com.squareup" and is declared in gradle.properties. It's set to a
// different value here to disambiguate the Maven coordinates of the :interop:javapoet submodule and the JavaPoet
// dependency.
group = "com.squareup.kotlinpoet"
version = property("VERSION_NAME") as String
repositories {
mavenCentral()
}
}
subprojects {
tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
freeCompilerArgs.add("-Xjvm-default=all")
}
}
// Ensure "org.gradle.jvm.version" is set to "8" in Gradle metadata.
tasks.withType<JavaCompile> {
options.release = 8
}
if ("test" !in name && buildFile.exists()) {
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "com.vanniktech.maven.publish")
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
configure<KotlinMultiplatformExtension> {
explicitApi()
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
configure<KotlinProjectExtension> {
explicitApi()
}
}
afterEvaluate {
tasks.named<DokkaTask>("dokkaHtml") {
val projectFolder = project.path.trim(':').replace(':', '-')
outputDirectory = rootProject.rootDir.resolve("docs/1.x/$projectFolder")
dokkaSourceSets.configureEach {
skipDeprecated = true
}
}
}
}
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
kotlin {
target("**/*.kt")
ktlint(libs.versions.ktlint.get()).editorConfigOverride(
mapOf("ktlint_standard_filename" to "disabled"),
)
trimTrailingWhitespace()
endWithNewline()
licenseHeader(
"""
|/*
| * Copyright (C) ${'$'}YEAR Square, Inc.
| *
| * Licensed under the Apache License, Version 2.0 (the "License");
| * you may not use this file except in compliance with the License.
| * You may obtain a copy of the License at
| *
| * https://www.apache.org/licenses/LICENSE-2.0
| *
| * Unless required by applicable law or agreed to in writing, software
| * distributed under the License is distributed on an "AS IS" BASIS,
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| * See the License for the specific language governing permissions and
| * limitations under the License.
| */
""".trimMargin(),
)
}
}
// Only enable the extra toolchain tests on CI. Otherwise local development is broken on Apple Silicon macs
// because there are no matching toolchains for several older JDK versions.
if ("CI" in System.getenv()) {
fun Project.setupCheckTask(testTaskName: String) {
// Copied from https://github.com/square/retrofit/blob/master/retrofit/build.gradle#L28.
// Create a test task for each supported JDK. We check every "LTS" + current version.
val versionsToTest = listOf(8, 11, 17, 21, 23)
for (majorVersion in versionsToTest) {
val jdkTest = tasks.register<Test>("testJdk$majorVersion") {
val javaToolchains = project.extensions.getByType(JavaToolchainService::class)
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(majorVersion)
vendor = JvmVendorSpec.AZUL
}
description = "Runs the test suite on JDK $majorVersion"
group = LifecycleBasePlugin.VERIFICATION_GROUP
// Copy inputs from normal Test task.
val testTask =
tasks.getByName<Test>(testTaskName)
classpath = testTask.classpath
testClassesDirs = testTask.testClassesDirs
testLogging {
exceptionFormat = TestExceptionFormat.FULL
}
}
tasks.named("check").configure {
dependsOn(jdkTest)
}
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
setupCheckTask("jvmTest")
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
setupCheckTask("test")
}
}
}
apiValidation {
nonPublicMarkers += "com.squareup.kotlinpoet.ExperimentalKotlinPoetApi"
ignoredProjects += listOf(
"interop", // Empty middle package
"test-processor", // Test only
)
}