-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
187 lines (158 loc) · 5.01 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* Copyright (C) 2021 Rick Busarow
* 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
*
* http://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 io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
import io.gitlab.arturbosch.detekt.detekt
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask
buildscript {
repositories {
mavenCentral()
google()
maven("https://plugins.gradle.org/m2/")
maven("https://oss.sonatype.org/content/repositories/snapshots")
}
dependencies {
classpath(libs.android.gradle)
classpath(libs.google.ksp)
classpath(libs.kotlin.gradle.plug)
classpath(libs.ktlint.gradle)
classpath(libs.square.anvil.gradle)
classpath(libs.vanniktech.maven.publish)
}
}
plugins {
kotlin("jvm")
id("com.github.ben-manes.versions") version "0.39.0"
id("io.gitlab.arturbosch.detekt") version "1.18.1"
id("com.rickbusarow.module-check") version "0.11.3"
id("com.osacky.doctor") version "0.7.3"
id("com.dorongold.task-tree") version "2.1.0"
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.8.0"
base
dokka
knit
website
}
allprojects {
repositories {
google()
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/snapshots")
}
configurations.all {
resolutionStrategy {
eachDependency {
when {
requested.group == "org.jetbrains.kotlin" -> useVersion(libs.versions.kotlin.get())
}
}
}
}
}
@Suppress("DEPRECATION")
detekt {
parallel = true
config = files("$rootDir/detekt/detekt-config.yml")
reports {
xml.enabled = false
html.enabled = true
txt.enabled = false
}
}
tasks.withType<DetektCreateBaselineTask> {
setSource(files(rootDir))
include("**/*.kt", "**/*.kts")
exclude("**/resources/**", "**/build/**", "**/src/test/java**")
// Target version of the generated JVM bytecode. It is used for type resolution.
this.jvmTarget = "1.8"
}
tasks.withType<Detekt> {
setSource(files(rootDir))
include("**/*.kt", "**/*.kts")
exclude("**/resources/**", "**/build/**", "**/src/test/java**", "**/src/test/kotlin**")
// Target version of the generated JVM bytecode. It is used for type resolution.
this.jvmTarget = "1.8"
}
fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}
tasks.named(
"dependencyUpdates",
com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask::class.java
).configure {
rejectVersionIf {
isNonStable(candidate.version) && !isNonStable(currentVersion)
}
}
allprojects {
apply(plugin = "org.jlleitschuh.gradle.ktlint")
configure<KtlintExtension> {
debug.set(false)
disabledRules.set(
setOf(
"no-wildcard-imports",
"max-line-length", // manually formatting still does this, and KTLint will still wrap long chains when possible
"filename", // same as Detekt's MatchingDeclarationName, but Detekt's version can be suppressed and this can't
"experimental:argument-list-wrapping" // doesn't work half the time
)
)
}
tasks.withType<BaseKtLintCheckTask> {
workerMaxHeapSize.set("512m")
}
}
apiValidation {
/**
* Packages that are excluded from public API dumps even if they
* contain public API.
*/
// ignoredPackages.add()
/**
* Sub-projects that are excluded from API validation
*/
ignoredProjects.addAll(
listOf()
)
/**
* Set of annotations that exclude API from being public.
* Typically, it is all kinds of `@InternalApi` annotations that mark
* effectively private API that cannot be actually private for technical reasons.
*/
// nonPublicMarkers.add()
}
// Delete any empty directories while cleaning.
// This is mostly just because IntelliJ/AS likes to randomly create both `/java` and `/kotlin`
// source directories and that annoys me.
allprojects {
val proj = this@allprojects
proj.tasks
.withType<Delete>()
.configureEach {
doLast {
val subprojectDirs = proj.subprojects
.map { it.projectDir.path }
proj.projectDir.walkBottomUp()
.filter { it.isDirectory }
.filterNot { dir -> subprojectDirs.any { dir.path.startsWith(it) } }
.filterNot { it.path.contains(".gradle") }
.filter { it.listFiles()?.isEmpty() != false }
.forEach { it.deleteRecursively() }
}
}
}