-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle.kts
159 lines (138 loc) · 4.98 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
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.LibraryPlugin
import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessExtensionPredeclare
import com.diffplug.gradle.spotless.SpotlessPlugin
import com.diffplug.spotless.LineEnding
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektPlugin
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.mavenPublish) apply false
alias(libs.plugins.kotlinx.binaryCompatibilityValidator)
alias(libs.plugins.dokka)
alias(libs.plugins.spotless)
alias(libs.plugins.detekt)
alias(libs.plugins.buildconfig) apply false
alias(libs.plugins.wire) apply false
alias(libs.plugins.ksp) apply false
}
tasks.dokkaHtmlMultiModule {
moduleName.set("Laboratory")
moduleVersion.set(project.property("VERSION_NAME") as String)
outputDirectory.set(rootDir.resolve("docs/api"))
}
val javaTarget = JvmTarget.fromTarget(libs.versions.jvmTarget.get())
val ktlintVersion = libs.versions.ktlint.get()
val mavenPublishId = libs.plugins.mavenPublish.get().pluginId
allprojects {
val configureSpotless: SpotlessExtension.() -> Unit = {
lineEndings = LineEnding.UNIX
kotlin {
target("src/**/*.kt")
trimTrailingWhitespace()
endWithNewline()
ktlint(ktlintVersion).setEditorConfigPath(rootProject.file(".editorconfig"))
}
kotlinGradle {
target("*.kts")
trimTrailingWhitespace()
endWithNewline()
ktlint(ktlintVersion).setEditorConfigPath(rootProject.file(".editorconfig"))
}
format("misc") {
target("*.md", "*.yml", "*.proto", "*.properties", "*.toml", "*.xml", "*.txt", "*.html", "*.css", ".gitignore", ".editorconfig")
trimTrailingWhitespace()
endWithNewline()
}
}
plugins.withType<SpotlessPlugin>().configureEach {
configure<SpotlessExtension> {
configureSpotless()
if (project.rootProject == project) {
predeclareDeps()
}
}
if (project.rootProject == project) {
configure<SpotlessExtensionPredeclare> { configureSpotless() }
}
}
plugins.withType<DetektPlugin>().configureEach {
configure<DetektExtension> {
toolVersion = libs.versions.detekt.get()
allRules = true
parallel = true
buildUponDefaultConfig = true
config.from(rootProject.file("detekt.yml"))
}
tasks.withType<Detekt>().configureEach {
jvmTarget = javaTarget.target
reports {
html.required.set(true)
xml.required.set(true)
txt.required.set(true)
}
}
}
}
subprojects {
group = project.property("GROUP") as String
version = project.property("VERSION_NAME") as String
plugins.withType<KotlinBasePlugin>().configureEach {
tasks.withType<KotlinCompilationTask<KotlinJvmCompilerOptions>>().configureEach {
compilerOptions {
jvmTarget.set(javaTarget)
progressiveMode.set(true)
allWarningsAsErrors.set(true)
optIn.addAll("kotlin.RequiresOptIn")
freeCompilerArgs.addAll("-Xjvm-default=all")
}
}
configure<KotlinProjectExtension> { explicitApi() }
}
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = javaTarget.target
targetCompatibility = javaTarget.target
}
tasks.withType<Test>().configureEach { testLogging.events("skipped", "failed", "passed") }
plugins.withType<LibraryPlugin>().configureEach {
configure<LibraryExtension> {
compileOptions {
sourceCompatibility = JavaVersion.toVersion(javaTarget.target)
targetCompatibility = JavaVersion.toVersion(javaTarget.target)
}
compileSdk = libs.versions.compileSdk.get().toInt()
defaultConfig.minSdk = libs.versions.minSdk.get().toInt()
testOptions.targetSdk = libs.versions.targetSdk.get().toInt()
lint {
lintConfig = rootProject.file("lint.xml")
warningsAsErrors = true
htmlReport = true
xmlReport = true
textReport = true
checkGeneratedSources = true
checkTestSources = false
checkReleaseBuilds = false // Execute explicitly on CI instead
}
}
configure<LibraryAndroidComponentsExtension> {
beforeVariants { builder -> builder.enable = builder.buildType == "release" }
}
}
pluginManager.withPlugin(mavenPublishId) {
configure<MavenPublishBaseExtension> {
publishToMavenCentral()
signAllPublications()
}
}
}