1 /*
2 * Copyright (C) 2019 Square, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 import com.diffplug.gradle.spotless.SpotlessExtension
17 import org.jetbrains.dokka.gradle.DokkaTask
18 import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
19 import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
20
<lambda>null21 plugins {
22 alias(libs.plugins.kotlin.jvm) apply false
23 alias(libs.plugins.ksp) apply false
24 alias(libs.plugins.dokka) apply false
25 alias(libs.plugins.spotless) apply false
26 alias(libs.plugins.mavenPublish) apply false
27 alias(libs.plugins.kotlinBinaryCompatibilityValidator)
28 }
29
<lambda>null30 allprojects {
31 group = property("GROUP") as String
32 version = property("VERSION_NAME") as String
33
34 repositories {
35 mavenCentral()
36 }
37 }
38
<lambda>null39 subprojects {
40 tasks.withType<KotlinCompile> {
41 kotlinOptions {
42 freeCompilerArgs += listOf("-opt-in=kotlin.RequiresOptIn")
43 }
44 }
45 // Ensure "org.gradle.jvm.version" is set to "8" in Gradle metadata.
46 tasks.withType<JavaCompile> {
47 sourceCompatibility = JavaVersion.VERSION_1_8.toString()
48 targetCompatibility = JavaVersion.VERSION_1_8.toString()
49 }
50
51 apply(plugin = "org.jetbrains.kotlin.jvm")
52 if ("test" !in name && buildFile.exists()) {
53 apply(plugin = "org.jetbrains.dokka")
54 apply(plugin = "com.vanniktech.maven.publish")
55 configure<KotlinProjectExtension> {
56 explicitApi()
57 }
58 afterEvaluate {
59 tasks.named<DokkaTask>("dokkaHtml") {
60 val projectFolder = project.path.trim(':').replace(':', '-')
61 outputDirectory.set(rootProject.rootDir.resolve("docs/1.x/$projectFolder"))
62 dokkaSourceSets.configureEach {
63 skipDeprecated.set(true)
64 }
65 }
66 }
67 }
68
69 apply(plugin = "com.diffplug.spotless")
70 configure<SpotlessExtension> {
71 kotlin {
72 target("**/*.kt")
73 ktlint(libs.versions.ktlint.get()).editorConfigOverride(
74 mapOf("ktlint_standard_filename" to "disabled"),
75 )
76 trimTrailingWhitespace()
77 endWithNewline()
78
79 licenseHeader(
80 """
81 |/*
82 | * Copyright (C) ${'$'}YEAR Square, Inc.
83 | *
84 | * Licensed under the Apache License, Version 2.0 (the "License");
85 | * you may not use this file except in compliance with the License.
86 | * You may obtain a copy of the License at
87 | *
88 | * https://www.apache.org/licenses/LICENSE-2.0
89 | *
90 | * Unless required by applicable law or agreed to in writing, software
91 | * distributed under the License is distributed on an "AS IS" BASIS,
92 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
93 | * See the License for the specific language governing permissions and
94 | * limitations under the License.
95 | */
96 """.trimMargin()
97 )
98 }
99 }
100
101 // Copied from https://github.com/square/retrofit/blob/master/retrofit/build.gradle#L28.
102 // Create a test task for each supported JDK.
103 for (majorVersion in 8..18) {
104 // Adoptium JDK 9 cannot extract on Linux or Mac OS.
105 if (majorVersion == 9) continue
106 // Started causing build failures in late 2022, e.g.:
107 // https://github.com/square/kotlinpoet/actions/runs/3816320722/jobs/6531532305.
108 if (majorVersion == 10) continue
109
110 val jdkTest = tasks.register<Test>("testJdk$majorVersion") {
111 val javaToolchains = project.extensions.getByType(JavaToolchainService::class)
112 javaLauncher.set(javaToolchains.launcherFor {
113 languageVersion.set(JavaLanguageVersion.of(majorVersion))
114 })
115
116 description = "Runs the test suite on JDK $majorVersion"
117 group = LifecycleBasePlugin.VERIFICATION_GROUP
118
119 // Copy inputs from normal Test task.
120 val testTask = tasks.getByName<Test>("test")
121 classpath = testTask.classpath
122 testClassesDirs = testTask.testClassesDirs
123 }
124 tasks.named("check").configure {
125 dependsOn(jdkTest)
126 }
127 }
128 }
129
<lambda>null130 apiValidation {
131 nonPublicMarkers += "com.squareup.kotlinpoet.ExperimentalKotlinPoetApi"
132 ignoredProjects += listOf(
133 "interop", // Empty middle package
134 "test-processor" // Test only
135 )
136 }
137