-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle.kts
152 lines (136 loc) · 4.61 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
// Copyright (C) 2024 r0adkll
// SPDX-License-Identifier: Apache-2.0
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.LibraryExtension
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.diffplug.gradle.spotless.SpotlessExtension
import com.diffplug.gradle.spotless.SpotlessExtensionPredeclare
import com.diffplug.spotless.LineEnding
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import java.net.URI
import org.jetbrains.dokka.gradle.DokkaTaskPartial
plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.compose.multiplatform) apply false
alias(libs.plugins.dokka)
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.kotlinParcelize) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.mavenPublish) apply false
alias(libs.plugins.spotless)
}
allprojects {
apply(plugin = "com.diffplug.spotless")
val spotlessFormatters: SpotlessExtension.() -> Unit = {
lineEndings = LineEnding.PLATFORM_NATIVE
format("misc") {
target("*.md", ".gitignore")
endWithNewline()
}
kotlin {
target("src/**/*.kt")
ktlint(libs.versions.ktlint.get())
trimTrailingWhitespace()
endWithNewline()
targetExclude("**/spotless.kt")
}
kotlinGradle {
target("*.kts")
ktlint(libs.versions.ktlint.get())
trimTrailingWhitespace()
endWithNewline()
licenseHeaderFile(
rootProject.file("spotless/spotless.kt"),
"(import|plugins|buildscript|dependencies|pluginManagement|dependencyResolutionManagement)",
)
}
// Apply license formatting separately for kotlin files so we can prevent it from overwriting
// copied files
format("license") {
licenseHeaderFile(rootProject.file("spotless/spotless.kt"), "(package|@file:)")
target("src/**/*.kt")
}
}
configure<SpotlessExtension> {
spotlessFormatters()
if (project.rootProject == project) {
predeclareDeps()
}
}
if (project.rootProject == project) {
configure<SpotlessExtensionPredeclare> { spotlessFormatters() }
}
}
subprojects {
val isPublished = project.hasProperty("POM_ARTIFACT_ID")
pluginManager.withPlugin("com.vanniktech.maven.publish") {
apply(plugin = "org.jetbrains.dokka")
tasks.withType<DokkaTaskPartial>().configureEach {
moduleName.set(project.path.removePrefix(":").replace(":", "/"))
outputDirectory.set(layout.buildDirectory.dir("docs/partial"))
dokkaSourceSets.configureEach {
val readMeProvider = project.layout.projectDirectory.file("README.md")
if (readMeProvider.asFile.exists()) {
includes.from(readMeProvider)
}
if (name.contains("androidTest", ignoreCase = true)) {
suppress.set(true)
}
skipDeprecated.set(true)
// Skip internal packages
perPackageOption {
// language=RegExp
matchingRegex.set(".*\\.internal\\..*")
suppress.set(true)
}
// AndroidX and Android docs are automatically added by the Dokka plugin.
// Add source links
sourceLink {
localDirectory.set(layout.projectDirectory.dir("src").asFile)
val relPath = rootProject.projectDir.toPath().relativize(projectDir.toPath())
remoteUrl.set(
providers.gradleProperty("POM_SCM_URL").map { scmUrl ->
URI("$scmUrl/tree/main/$relPath/src").toURL()
},
)
remoteLineSuffix.set("#L")
}
}
}
configure<MavenPublishBaseExtension> {
publishToMavenCentral(automaticRelease = true)
signAllPublications()
}
}
// Common android config
val commonAndroidConfig: CommonExtension<*, *, *, *, *, *>.() -> Unit = {
compileSdk = 34
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
// Android library config
pluginManager.withPlugin("com.android.library") {
with(extensions.getByType<LibraryExtension>()) {
commonAndroidConfig()
defaultConfig { minSdk = 21 }
testOptions { targetSdk = 34 }
}
// Single-variant libraries
extensions.configure<LibraryAndroidComponentsExtension> {
beforeVariants { builder ->
if (builder.buildType == "debug") {
builder.enable = false
}
}
}
}
}
tasks.register<Copy>("bootstrap") {
from(file("scripts/pre-push"))
into(file(".git/hooks"))
}