forked from ZacSweers/MoshiX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
165 lines (158 loc) · 5.48 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
/*
* Copyright (C) 2020 Zac Sweers
*
* 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 org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URL
buildscript {
dependencies {
classpath(kotlin("gradle-plugin", version = Dependencies.Kotlin.version))
}
}
plugins {
kotlin("jvm") version Dependencies.Kotlin.version apply false
id("org.jetbrains.dokka") version Dependencies.Kotlin.dokkaVersion apply false
id("com.vanniktech.maven.publish") version "0.15.1" apply false
id("com.diffplug.spotless") version "5.12.4"
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.5.0"
}
apiValidation {
ignoredProjects.addAll(
listOf(
/* :moshi-ksp: */ "extra-moshi-test-module",
/* :moshi-ksp: */ "tests",
/* :moshi-sealed: */ "sample"
)
)
}
spotless {
format("misc") {
target("*.md", ".gitignore")
trimTrailingWhitespace()
indentWithSpaces(2)
endWithNewline()
}
// TODO re-enable after GJF supports sealed
// https://github.com/google/google-java-format/issues/603
// if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16)) {
// val configureCommonJavaFormat: JavaExtension.() -> Unit = {
// googleJavaFormat("1.10.0")
// }
// java {
// configureCommonJavaFormat()
// target("**/*.java")
// targetExclude(
// "**/spotless.java",
// "**/build/**"
// )
// licenseHeaderFile("spotless/spotless.java")
// }
// }
kotlin {
ktlint(Dependencies.ktlintVersion).userData(mapOf("indent_size" to "2"))
target("**/*.kt")
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile("spotless/spotless.kt")
.updateYearWithLatest(false)
targetExclude(
"**/Dependencies.kt", "**/spotless.kt", "**/build/**", "**/moshi-ksp/tests/**",
"**/moshi-ksp/moshi-ksp/src/main/kotlin/dev/zacsweers/moshix/ksp/shade/**"
)
}
// format("externalKotlin", KotlinExtension::class.java) {
// // These don't use our spotless config for header files since we don't want to overwrite the
// // existing copyright headers.
// configureCommonKotlinFormat()
// }
kotlinGradle {
ktlint(Dependencies.ktlintVersion).userData(mapOf("indent_size" to "2"))
target("**/*.gradle.kts")
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile("spotless/spotless.kts", "(import|plugins|buildscript|dependencies|pluginManagement)")
}
}
subprojects {
repositories {
mavenCentral()
google()
// Kotlin bootstrap repository, useful for testing against Kotlin dev builds. Usually only tested on CI shadow jobs
// https://kotlinlang.slack.com/archives/C0KLZSCHF/p1616514468003200?thread_ts=1616509748.001400&cid=C0KLZSCHF
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap") {
name = "Kotlin-Bootstrap"
content {
// this repository *only* contains Kotlin artifacts (don't try others here)
includeGroupByRegex("org\\.jetbrains.*")
}
}
}
val toolChainVersion = project.findProperty("moshix.javaLanguageVersion")?.toString() ?: "8"
val release = toolChainVersion.toInt()
val usePreview = project.hasProperty("moshix.javaPreview")
pluginManager.withPlugin("java") {
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(toolChainVersion))
}
}
project.tasks.withType<JavaCompile>().configureEach {
options.release.set(release)
if (usePreview) {
options.compilerArgs.add("--enable-preview")
}
}
if (usePreview) {
project.tasks.withType<Test>().configureEach {
// TODO why doesn't add() work?
// jvmArgs!!.add("--enable-preview")
jvmArgs = listOf("--enable-preview")
}
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = Dependencies.Kotlin.jvmTarget
@Suppress("SuspiciousCollectionReassignment")
freeCompilerArgs += Dependencies.Kotlin.defaultFreeCompilerArgs
// TODO disabled because Gradle's Kotlin handling is silly
// https://github.com/gradle/gradle/issues/16779
// allWarningsAsErrors = true
}
}
if (project.name != "sample" && !project.path.contains("sample") && !project.path.contains("test")) {
configure<KotlinProjectExtension> {
explicitApi()
}
}
}
pluginManager.withPlugin("com.vanniktech.maven.publish") {
apply(plugin = "org.jetbrains.dokka")
tasks.named<DokkaTask>("dokkaHtml") {
outputDirectory.set(rootProject.rootDir.resolve("docs/0.x"))
dokkaSourceSets.configureEach {
skipDeprecated.set(true)
externalDocumentationLink {
url.set(URL("https://square.github.io/okio/2.x/okio/"))
}
externalDocumentationLink {
url.set(URL("https://square.github.io/moshi/1.x/moshi/"))
}
}
}
}
}