-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
build.gradle.kts
218 lines (189 loc) · 7.75 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import com.diffplug.spotless.LineEnding
import com.vanniktech.maven.publish.MavenPublishPlugin
import com.vanniktech.maven.publish.MavenPublishPluginExtension
import io.gitlab.arturbosch.detekt.Detekt
import java.util.zip.ZipFile
plugins {
id(Config.gradleMavenPublishPlugin).version(Config.gradleMavenPublishPluginVersion)
id(Config.QualityPlugins.spotless).version(Config.QualityPlugins.spotlessVersion)
id(Config.QualityPlugins.detekt).version(Config.QualityPlugins.detektVersion)
id(Config.dokka).version(Config.dokkaVersion)
kotlin(Config.multiplatform).version(Config.kotlinVersion).apply(false)
kotlin(Config.cocoapods).version(Config.kotlinVersion).apply(false)
id(Config.jetpackCompose).version(Config.composeVersion).apply(false)
id(Config.androidGradle).version(Config.agpVersion).apply(false)
id(Config.BuildPlugins.buildConfig).version(Config.BuildPlugins.buildConfigVersion).apply(false)
kotlin(Config.kotlinSerializationPlugin).version(Config.kotlinVersion).apply(false)
id(Config.QualityPlugins.kover).version(Config.QualityPlugins.koverVersion).apply(false)
id(Config.QualityPlugins.binaryCompatibility).version(Config.QualityPlugins.binaryCompatibilityVersion)
.apply(false)
}
allprojects {
group = Config.Sentry.group
version = properties["versionName"].toString()
}
subprojects {
if (this.name.contains("sentry-kotlin-multiplatform")) {
apply<DistributionPlugin>()
val sep = File.separator
configure<DistributionContainer> {
this.configureForMultiplatform(this@subprojects)
}
tasks.named("distZip").configure {
this.dependsOn("publishToMavenLocal")
this.doLast {
val distributionFilePath =
"${this.project.buildDir}${sep}distributions${sep}${this.project.name}-${this.project.version}.zip"
val file = File(distributionFilePath)
if (!file.exists()) throw GradleException("Distribution file: $distributionFilePath does not exist")
if (file.length() == 0L) throw GradleException("Distribution file: $distributionFilePath is empty")
}
}
afterEvaluate {
val platformDists = project.tasks.filter { task ->
task.name.matches(Regex("(.*)DistZip"))
}.toTypedArray()
project.tasks.getByName("distZip").finalizedBy(*platformDists)
apply<MavenPublishPlugin>()
configure<MavenPublishPluginExtension> {
// signing is done when uploading files to MC
// via gpg:sign-and-deploy-file (release.kts)
releaseSigningEnabled = false
}
}
}
}
tasks.register("validateDistributions") {
subprojects {
val subproject = this@subprojects
if (subproject.name == "sentry-kotlin-multiplatform") {
subproject.validateKotlinMultiplatformCoreArtifacts()
}
}
}
private fun Project.validateKotlinMultiplatformCoreArtifacts() {
val distributionDir = project.layout.buildDirectory.dir("distributions").get().asFile
val expectedNumOfFiles = 15
val filesList = distributionDir.listFiles()
val actualNumOfFiles = filesList?.size ?: 0
if (actualNumOfFiles == expectedNumOfFiles) {
println("✅ Found $actualNumOfFiles distribution files as expected.")
} else {
throw GradleException("❌ Expected $expectedNumOfFiles distribution files, but found $actualNumOfFiles")
}
val baseFileName = "sentry-kotlin-multiplatform"
val platforms = listOf(
"watchosx64", "watchossimulatorarm64", "watchosarm64", "watchosarm32",
"tvosx64", "tvossimulatorarm64", "tvosarm64",
"macosx64", "macosarm64",
"jvm",
"iosx64", "iossimulatorarm64", "iosarm64",
"android"
)
val artifactPaths = buildList {
add(distributionDir.resolve("$baseFileName-$version.zip"))
addAll(
platforms.map { platform ->
distributionDir.resolve("$baseFileName-$platform-$version.zip")
}
)
}
val commonRequiredEntries = listOf(
"javadoc",
"sources",
"module",
"pom-default.xml"
)
artifactPaths.forEach { artifactFile ->
if (!artifactFile.exists()) {
throw GradleException("❌ Artifact file: ${artifactFile.path} does not exist")
}
if (artifactFile.length() == 0L) {
throw GradleException("❌ Artifact file: ${artifactFile.path} is empty")
}
ZipFile(artifactFile).use { zip ->
val entries = zip.entries().asSequence().map { it.name }.toList()
commonRequiredEntries.forEach { requiredEntry ->
if (entries.none { it.contains(requiredEntry) }) {
throw GradleException("❌ $requiredEntry not found in ${artifactFile.name}")
} else {
println("✅ Found $requiredEntry in ${artifactFile.name}")
}
}
when {
artifactFile.name.contains("ios", ignoreCase = true) ||
artifactFile.name.contains("macos", ignoreCase = true) ||
artifactFile.name.contains("watchos", ignoreCase = true) ||
artifactFile.name.contains("tvos", ignoreCase = true) -> {
val expectedNumOfKlibFiles = 3
val actualKlibFiles = entries.count { it.contains("klib") }
if (actualKlibFiles != expectedNumOfKlibFiles) {
throw GradleException("❌ Expected $expectedNumOfKlibFiles klib files in ${artifactFile.name}, but found $actualKlibFiles")
} else {
println("✅ Found $expectedNumOfKlibFiles klib files in ${artifactFile.name}")
}
}
artifactFile.name.contains("android", ignoreCase = true) -> {
if (entries.none { it.contains("aar") }) {
throw GradleException("❌ aar file not found in ${artifactFile.name}")
} else {
println("✅ Found aar file in ${artifactFile.name}")
}
}
}
}
}
}
subprojects {
if (project.name.contains("sentry-kotlin-multiplatform")) {
apply(plugin = Config.dokka)
}
}
spotless {
lineEndings = LineEnding.UNIX
kotlin {
target("**/*.kt")
targetExclude("**/generated/**/*.kt")
ktlint()
}
kotlinGradle {
target("**/*.kts")
targetExclude("**/generated/**/*.kts")
ktlint()
}
}
val detektConfigFilePath = "$rootDir/config/detekt/detekt.yml"
val detektBaselineFilePath = "$rootDir/config/detekt/baseline.xml"
detekt {
buildUponDefaultConfig = true
config = files(detektConfigFilePath)
baseline = file(detektBaselineFilePath)
}
fun SourceTask.detektExcludes() {
exclude("**/build/**")
exclude("**/*.kts")
exclude("**/buildSrc/**")
exclude("**/*Test*/**")
exclude("**/resources/**")
exclude("**/sentry-samples/**")
}
tasks.withType<Detekt>().configureEach {
reports {
html.required.set(true)
}
setSource(files(project.projectDir))
detektExcludes()
}
/** Task for generating a Detekt baseline.xml */
val detektProjectBaseline by tasks.registering(io.gitlab.arturbosch.detekt.DetektCreateBaselineTask::class) {
buildUponDefaultConfig.set(true)
setSource(files(rootDir))
config.setFrom(files(detektConfigFilePath))
baseline.set(file(detektBaselineFilePath))
include("**/*.kt")
detektExcludes()
}
// Configure tasks so it is also run for the plugin
tasks.getByName("detekt") {
gradle.includedBuild("sentry-kotlin-multiplatform-gradle-plugin").task(":detekt")
}