-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.gradle.kts
165 lines (151 loc) · 5.99 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) 2023 Salesforce, Inc.
// SPDX-License-Identifier: Apache-2.0
import com.android.build.gradle.internal.lint.AndroidLintAnalysisTask
import com.android.build.gradle.internal.lint.LintModelWriterTask
import com.diffplug.gradle.spotless.KotlinExtension
import com.diffplug.gradle.spotless.SpotlessExtension
import com.google.devtools.ksp.gradle.KspTask
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.dokka.gradle.DokkaExtension
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
}
val ktfmtVersion = libs.versions.ktfmt.get()
val pathPrefix = "src/main/java/slack/lint/compose"
val utilPathPrefix = "$pathPrefix/util"
val testPathPrefix = "src/test/java/slack/lint/compose"
val externalFiles =
arrayOf(
"$utilPathPrefix/ASTNodes.kt",
"$utilPathPrefix/Composables.kt",
"$utilPathPrefix/KotlinUtils.kt",
"$utilPathPrefix/KtAnnotateds.kt",
"$utilPathPrefix/KtCallableDeclarations.kt",
"$utilPathPrefix/KtFunctions.kt",
"$utilPathPrefix/Previews.kt",
"$utilPathPrefix/Priorities",
"$utilPathPrefix/PsiElements.kt",
"$pathPrefix/ComposableFunctionDetector.kt",
"$pathPrefix/ComposableFunctionNamingDetector.kt",
"$pathPrefix/CompositionLocalUsageDetector.kt",
"$pathPrefix/ContentEmitterReturningValuesDetector.kt",
"$pathPrefix/ModifierComposableDetector.kt",
"$pathPrefix/ModifierMissingDetector.kt",
"$pathPrefix/ModifierReusedDetector.kt",
"$pathPrefix/ModifierWithoutDefaultDetector.kt",
"$pathPrefix/MultipleContentEmittersDetector.kt",
"$pathPrefix/MutableParametersDetector.kt",
"$pathPrefix/ParameterOrderDetector.kt",
"$pathPrefix/PreviewNamingDetector.kt",
"$pathPrefix/PreviewPublicDetector.kt",
"$pathPrefix/RememberMissingDetector.kt",
"$pathPrefix/UnstableCollectionsDetector.kt",
"$pathPrefix/ViewModelForwardingDetector.kt",
"$pathPrefix/ViewModelInjectionDetector.kt",
"$testPathPrefix/ComposableFunctionNamingDetectorTest.kt",
"$testPathPrefix/CompositionLocalUsageDetectorTest.kt",
"$testPathPrefix/ContentEmitterReturningValuesDetectorTest.kt",
"$testPathPrefix/ModifierComposableDetectorTest.kt",
"$testPathPrefix/ModifierMissingDetectorTest.kt",
"$testPathPrefix/ModifierReusedDetectorTest.kt",
"$testPathPrefix/ModifierWithoutDefaultDetectorTest.kt",
"$testPathPrefix/MultipleContentEmittersDetectorTest.kt",
"$testPathPrefix/MutableParametersDetectorTest.kt",
"$testPathPrefix/ParameterOrderDetectorTest.kt",
"$testPathPrefix/PreviewNamingDetectorTest.kt",
"$testPathPrefix/PreviewPublicDetectorTest.kt",
"$testPathPrefix/RememberMissingDetectorTest.kt",
"$testPathPrefix/UnstableCollectionsDetectorTest.kt",
"$testPathPrefix/ViewModelForwardingDetectorTest.kt",
"$testPathPrefix/ViewModelInjectionDetectorTest.kt",
)
allprojects {
apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
format("misc") {
target("*.md", ".gitignore")
trimTrailingWhitespace()
endWithNewline()
}
kotlin {
target("src/**/*.kt")
ktfmt(ktfmtVersion).googleStyle()
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(rootProject.file("spotless/spotless.kt"))
targetExclude("spotless/*.kt", "**/spotless/*.kt", *externalFiles)
}
// Externally adapted sources that should preserve their license header
format("kotlinExternal", KotlinExtension::class.java) {
target(*externalFiles)
ktfmt(ktfmtVersion).googleStyle()
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(rootProject.file("spotless/spotless-external.kt"))
}
kotlinGradle {
ktfmt(ktfmtVersion).googleStyle()
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(
rootProject.file("spotless/spotless.kt"),
"(import|plugins|buildscript|dependencies|pluginManagement)",
)
}
}
}
dokka {
dokkaPublications.html {
outputDirectory.set(rootDir.resolve("docs/api/1.x"))
includes.from(project.layout.projectDirectory.file("docs/index.md"))
}
}
dependencies { dokka(project(":compose-lint-checks")) }
subprojects {
pluginManager.withPlugin("java") {
configure<JavaPluginExtension> {
toolchain { languageVersion.set(libs.versions.jdk.map(JavaLanguageVersion::of)) }
}
tasks.withType<JavaCompile>().configureEach {
options.release.set(libs.versions.jvmTarget.map(String::toInt))
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
tasks.withType<KotlinCompile>().configureEach {
compilerOptions {
jvmTarget.set(libs.versions.jvmTarget.map(JvmTarget::fromTarget))
// TODO re-enable once lint uses Kotlin 1.5
// allWarningsAsErrors = true
// freeCompilerArgs = freeCompilerArgs + listOf("-progressive")
}
}
}
tasks.withType<Detekt>().configureEach { jvmTarget = libs.versions.jvmTarget.get() }
pluginManager.withPlugin("com.vanniktech.maven.publish") {
apply(plugin = "org.jetbrains.dokka")
configure<DokkaExtension> {
dokkaPublicationDirectory.set(layout.buildDirectory.dir("dokkaDir"))
dokkaSourceSets.configureEach { skipDeprecated.set(true) }
}
configure<MavenPublishBaseExtension> {
publishToMavenCentral(automaticRelease = true)
signAllPublications()
}
}
// TODO workaround for https://issuetracker.google.com/issues/269089135
pluginManager.withPlugin("com.google.devtools.ksp") {
tasks.withType<AndroidLintAnalysisTask>().configureEach {
mustRunAfter(tasks.withType<KspTask>())
}
tasks.withType<LintModelWriterTask>().configureEach { mustRunAfter(tasks.withType<KspTask>()) }
}
}