forked from slackhq/slack-lints
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
116 lines (102 loc) · 3.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
// Copyright (C) 2021 Slack Technologies, LLC
// SPDX-License-Identifier: Apache-2.0
import com.diffplug.gradle.spotless.KotlinExtension
import com.diffplug.gradle.spotless.SpotlessExtension
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.dokka.gradle.DokkaTaskPartial
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.spotless) apply false
alias(libs.plugins.mavenPublish) apply false
alias(libs.plugins.dokka)
alias(libs.plugins.detekt)
alias(libs.plugins.lint) apply false
alias(libs.plugins.ksp) apply false
}
tasks.dokkaHtmlMultiModule {
outputDirectory.set(rootDir.resolve("docs/api/0.x"))
includes.from(project.layout.projectDirectory.file("README.md"))
}
val ktfmtVersion = libs.versions.ktfmt.get()
allprojects {
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
format("misc") {
target("*.md", ".gitignore")
trimTrailingWhitespace()
endWithNewline()
}
val externalSourceGlobs =
arrayOf("**/denylistedapis/*.kt", "**/ExceptionMessageDetector*.kt", "**/util/Names.kt")
kotlin {
target("**/*.kt")
ktfmt(ktfmtVersion).googleStyle()
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(rootProject.file("spotless/spotless.kt"))
targetExclude("**/spotless.kt", *externalSourceGlobs)
}
// Externally adapted sources that should preserve their license header
format("kotlinExternal", KotlinExtension::class.java) {
target(*externalSourceGlobs)
ktfmt(ktfmtVersion).googleStyle()
trimTrailingWhitespace()
endWithNewline()
}
kotlinGradle {
ktfmt(ktfmtVersion).googleStyle()
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(
rootProject.file("spotless/spotless.kt"),
"(import|plugins|buildscript|dependencies|pluginManagement)",
)
}
}
}
val jdk = libs.versions.jdk.get().toInt()
val lintJvmTargetString: String = libs.versions.lintJvmTarget.get()
val runtimeJvmTargetString: String = libs.versions.runtimeJvmTarget.get()
subprojects {
val isChecksProject = path == ":slack-lint-checks"
val jvmTargetString =
if (isChecksProject) {
lintJvmTargetString
} else {
runtimeJvmTargetString
}
val jvmTargetInt = jvmTargetString.toInt()
pluginManager.withPlugin("java") {
configure<JavaPluginExtension> {
toolchain { languageVersion.set(JavaLanguageVersion.of(jdk)) }
}
tasks.withType<JavaCompile>().configureEach { options.release.set(jvmTargetInt) }
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.fromTarget(jvmTargetString))
// TODO re-enable on checks if lint ever targets latest kotlin versions
if (isChecksProject) {
allWarningsAsErrors.set(true)
progressiveMode.set(true)
}
}
}
}
tasks.withType<Detekt>().configureEach { jvmTarget = jvmTargetString }
pluginManager.withPlugin("com.vanniktech.maven.publish") {
apply(plugin = "org.jetbrains.dokka")
tasks.withType<DokkaTaskPartial>().configureEach {
outputDirectory.set(layout.buildDirectory.dir("docs/partial"))
dokkaSourceSets.configureEach { skipDeprecated.set(true) }
}
configure<MavenPublishBaseExtension> {
publishToMavenCentral(automaticRelease = true)
signAllPublications()
}
}
}