-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
368 lines (335 loc) · 12.6 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
import io.floodplain.build.FloodplainDeps
import io.floodplain.build.isReleaseVersion
import io.gitlab.arturbosch.detekt.Detekt
import java.io.File
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
maven("https://plugins.gradle.org/m2/")
mavenLocal()
}
dependencies {
classpath("gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.16.1")
// classpath("com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.6")
classpath("gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.2")
classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.18")
}
}
val buildKotlinVersion: String by extra
plugins {
kotlin("jvm") version "1.8.20"
id("org.jetbrains.kotlin.plugin.allopen") version "1.8.20"
id("org.jlleitschuh.gradle.ktlint") version "11.0.0"
id("org.jetbrains.dokka") version "1.8.10"
id("com.github.hierynomus.license-base").version("0.16.1")
id("com.github.spotbugs") version "5.0.12"
id("io.gitlab.arturbosch.detekt") version "1.21.0"
signing
`maven-publish`
`java-library`
jacoco
}
configurations.implementation {
exclude(group = "org.apache.kafka", module = "kafka-log4j-appender")
exclude(group = "log4j", module = "log4j")
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
dependencies {
implementation(io.floodplain.build.Libs.kotlin)
implementation("org.jetbrains.kotlin:kotlin-serialization")
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
google()
maven {
url = uri("https://packages.confluent.io/maven")
}
}
}
fun isKotlinModule(project: Project): Boolean {
val kotlinMainSource = project.projectDir.resolve("src/main/kotlin")
val kotlinTestSource = project.projectDir.resolve("src/test/kotlin")
return kotlinMainSource.exists() || kotlinTestSource.exists()
}
subprojects {
version = FloodplainDeps.floodplain_version
apply(plugin = "java")
apply(plugin = "eclipse")
apply(plugin = "maven-publish")
apply(plugin = "distribution")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "com.github.hierynomus.license-base")
apply(plugin = "jacoco")
// Crude exclusion for floodplain-direct, somehow seems to ignore exclude file TODO
if (!isKotlinModule(this) && this.name != "floodplain-direct") {
apply(plugin = "com.github.spotbugs")
spotbugs {
excludeFilter.set(rootProject.file("spotbugs-exclude.xml"))
}
}
if (!isKotlinModule(this)) {
// logger.warn("This project is not kotlin: ${this.name}")
tasks.withType<com.github.spotbugs.snom.SpotBugsTask>().configureEach {
// excludeFilter rootProject.file("spotbugs-exclude.xml")
// excludeFilter.fileValue(rootProject.file("spotbugs-exclude.xml"))
// baselineFile = file('spotbugs-baseline.xml')
// val f: File = rootProject.file("spotbugs-exclude.xml")
// excludeFilter.set(f)
// effort.set(com.github.spotbugs.snom.Effort.MAX)
reports.maybeCreate("xml").isEnabled = false
reports.maybeCreate("html").isEnabled = true
}
}
if (isKotlinModule(this)) {
apply(plugin = "io.gitlab.arturbosch.detekt")
detekt {
// Version of Detekt that will be used. When unspecified the latest detekt
// version found will be used. Override to stay on the same version.
toolVersion = "1.19.0"
// The directories where detekt looks for source files.
// Defaults to `files("src/main/java", "src/main/kotlin")`.
input = files("src/main/java", "src/main/kotlin")
config = files("${rootDir.path}/detektConfig.yml")
}
}
tasks.withType<com.hierynomus.gradle.license.tasks.LicenseFormat>().configureEach {
this.header = File(this.project.rootDir, "HEADER")
this.exclude("*.xml", "*.json")
this.mapping(mapOf("java" to "SLASHSTAR_STYLE", "kt" to "SLASHSTAR_STYLE"))
}
tasks.test {
useJUnitPlatform()
jvmArgs("--enable-preview")
finalizedBy(tasks.jacocoTestReport)
}
tasks.jacocoTestReport {
dependsOn(tasks.test)
classDirectories.setFrom(
files(
classDirectories.files.map {
fileTree(it) {
exclude("**/generated/**", "**/org/apache/**")
}
}
)
)
}
tasks.withType<com.hierynomus.gradle.license.tasks.LicenseCheck>().configureEach {
this.header = File(this.project.rootDir, "HEADER")
this.exclude("*.xml", "*.json")
this.mapping(mapOf("java" to "SLASHSTAR_STYLE", "kt" to "SLASHSTAR_STYLE"))
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "11"
kotlinOptions.javaParameters = true
kotlinOptions {
freeCompilerArgs = listOfNotNull(
"-Xjsr305=strict",
"-Xjvm-default=enable",
"-progressive",
"-Xopt-in=kotlin.RequiresOptIn",
"-Xopt-in=kotlin.ExperimentalUnsignedTypes",
"-Xopt-in=kotlin.ExperimentalStdlibApi",
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-Xopt-in=kotlin.time.ExperimentalTime"
)
}
}
val dokkaHtml by tasks.getting(org.jetbrains.dokka.gradle.DokkaTask::class)
tasks {
val sourcesJar by creating(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}
val javadocJar by creating(Jar::class) {
dependsOn.add(javadoc)
archiveClassifier.set("javadoc")
from(javadoc)
}
val dokkaJar by creating(Jar::class) {
dependsOn.add(dokkaHtml)
archiveClassifier.set("dokka")
from(dokkaHtml.outputDirectory)
}
artifacts {
archives(sourcesJar)
archives(javadocJar)
archives(dokkaJar)
archives(jar)
}
}
group = "io.floodplain"
publishing {
publications {
create<MavenPublication>(project.name) {
customizePom(this@create)
groupId = "io.floodplain"
artifactId = project.name
version = FloodplainDeps.floodplain_version
from(components["java"])
val sourcesJar by tasks
val javadocJar by tasks
val dokkaJar by tasks
artifact(sourcesJar)
artifact(javadocJar)
artifact(dokkaJar)
}
}
repositories {
maven {
name = "Snapshots"
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
credentials {
username = (project.findProperty("gpr.user") ?: System.getenv("CENTRAL_USERNAME") ?: "") as String
password = (project.findProperty("gpr.key") ?: System.getenv("CENTRAL_PASSWORD") ?: "") as String
}
}
maven {
name = "Staging"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = (project.findProperty("gpr.user") ?: System.getenv("CENTRAL_USERNAME") ?: "") as String
password = (project.findProperty("gpr.key") ?: System.getenv("CENTRAL_PASSWORD") ?: "") as String
}
}
}
}
apply(plugin = "signing")
signing {
if (isReleaseVersion()) {
sign(publishing.publications[project.name])
}
}
}
fun customizePom(publication: MavenPublication) {
with(publication.pom) {
withXml {
val root = asNode()
root.appendNode("name", "Floodplain")
root.appendNode("description", "Transforms CDC streams in Kotlin")
root.appendNode("url", "https://floodplain.nl")
}
organization {
name.set("Floodplain")
url.set("https://floodplain.nl")
}
issueManagement {
system.set("GitHub")
url.set("https://github.com/floodplainio/floodplain-library/issues")
}
licenses {
license {
name.set("Apache License 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("flyaruu")
name.set("Frank Lyaruu")
email.set("[email protected]")
}
}
scm {
url.set("https://github.com/floodplainio/floodplainio/floodplain-library")
connection.set("scm:git:git://github.com/floodplainio/floodplain-library.git")
developerConnection.set("scm:git:ssh://[email protected]:floodplainio/floodplain-library.git")
}
}
}
val detektAll by tasks.registering(Detekt::class) {
this.config.setFrom("${rootDir.path}/detektConfig.yml")
description = "Runs over whole code base without the starting overhead for each module."
parallel = true
buildUponDefaultConfig = true
setSource(files(projectDir))
// this.setConfig(files(project.rootDir.resolve("reports/failfast.yml")))
// config = files(project.rootDir.resolve("reports/failfast.yml"))
include("**/*.kt")
include("**/*.kts")
exclude("**/resources/**")
exclude("**/build/**")
// baseline.set(project.rootDir.resolve("reports/baseline.xml"))
reports {
xml.enabled = true
html.enabled = true
}
}
jacoco {
toolVersion = "0.8.7"
}
plugins.withType<JacocoPlugin> {
val testTasks = tasks.withType<Test>()
testTasks.configureEach {
extensions.configure<JacocoTaskExtension> {
// We don't want to collect coverage for third-party classes
// includes?.add("**/io.floodplain.*.class")
excludes?.add("**/generated/**")
excludes?.add("**/org/apache/**")
}
}
}
tasks.withType<JacocoReport> {
}
tasks.register<JacocoReport>("codeCoverageReport") {
// If a subproject applies the 'jacoco' plugin, add the result it to the report
val report = this
subprojects {
val subproject = this
subproject.plugins.withType<JacocoPlugin>().configureEach {
subproject.tasks.matching { it.extensions.findByType<JacocoTaskExtension>() != null }.configureEach {
val testTask = this
sourceSets(subproject.sourceSets.main.get())
// executionData(fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec"))
val execFiles = files(testTask).filter { it.exists() && it.name.endsWith(".exec") }
executionData(execFiles)
}
report.classDirectories.setFrom(
files(
classDirectories.files.map {
fileTree(it) {
exclude("**/generated/**", "**/org/apache/**", "**/io/floodplain/kotlindsl/example/**")
}
}
)
)
// To automatically run `test` every time `./gradlew codeCoverageReport` is called,
// you may want to set up a task dependency between them as shown below.
// Note that this requires the `test` tasks to be resolved eagerly (see `forEach`) which
// may have a negative effect on the configuration time of your build.
subproject.tasks.matching { it.extensions.findByType<JacocoTaskExtension>() != null }.forEach {
rootProject.tasks["codeCoverageReport"].dependsOn(it)
}
}
}
// enable the different report types (html, xml, csv)
reports {
// xml is usually used to integrate code coverage with
// other tools like SonarQube, Coveralls or Codecov
xml.required.set(true)
// HTML reports can be used to see code coverage
// without any external tools
html.required.set(true)
}
}
tasks.withType<Test> {
useJUnitPlatform {
includeEngines = setOf("junit-jupiter")
// this.includeTags = setOf("*")
}
testLogging {
events("passed", "skipped", "failed")
}
configure<JacocoTaskExtension> {
isEnabled = true
includes = listOf("**/io.floodplain.*.class")
}
}