/
module.gradle.kts
120 lines (109 loc) · 4.13 KB
/
module.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
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("packaging")
kotlin("jvm")
`maven-publish`
jacoco
}
// bundle detekt's version for all jars to use it at runtime
tasks.withType<Jar>().configureEach {
manifest {
attributes(mapOf("DetektVersion" to Versions.DETEKT))
}
}
val versionCatalog = project.extensions.getByType<VersionCatalogsExtension>().named("libs")
jacoco.toolVersion = versionCatalog.findVersion("jacoco").get().requiredVersion
tasks.withType<Test>().configureEach {
useJUnitPlatform()
systemProperty("spek2.jvm.cg.scan.concurrency", 1) // use one thread for classpath scanning
systemProperty("spek2.execution.test.timeout", 0) // disable test timeout
systemProperty("spek2.discovery.parallel.enabled", 0) // disable parallel test discovery
systemProperty("junit.jupiter.testinstance.lifecycle.default", "per_class")
val compileSnippetText: Boolean = if (project.hasProperty("compile-test-snippets")) {
(project.property("compile-test-snippets") as String).toBoolean()
} else {
false
}
systemProperty("compile-snippet-tests", compileSnippetText)
testLogging {
// set options for log level LIFECYCLE
events = setOf(
TestLogEvent.FAILED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT,
TestLogEvent.SKIPPED
)
exceptionFormat = TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
}
}
// Share sources folder with other projects for aggregated JaCoCo reports
configurations.create("transitiveSourcesElements") {
isVisible = false
isCanBeResolved = false
isCanBeConsumed = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("source-folders"))
}
sourceSets.main.get().withConvention(KotlinSourceSet::class) { kotlin }.srcDirs.forEach {
outgoing.artifact(it)
}
}
// Share the coverage data to be aggregated for the whole product
configurations.create("coverageDataElements") {
isVisible = false
isCanBeResolved = false
isCanBeConsumed = true
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data"))
}
// This will cause the test task to run if the coverage data is requested by the aggregation task
outgoing.artifact(
tasks.test.map { task ->
task.extensions.getByType<JacocoTaskExtension>().destinationFile!!
}
)
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = Versions.JVM_TARGET
apiVersion = "1.4"
freeCompilerArgs = listOf(
"-progressive",
"-Xsuppress-version-warnings",
"-opt-in=kotlin.RequiresOptIn"
)
// Usage: <code>./gradlew build -PwarningsAsErrors=true</code>.
// Note: currently there are warnings for detekt-gradle-plugin that seemingly can't be fixed
// until Gradle releases an update (https://github.com/gradle/gradle/issues/16345)
allWarningsAsErrors = when (project.name) {
"detekt-gradle-plugin" -> false
else -> (project.findProperty("warningsAsErrors") == "true" || System.getenv("CI") == "true")
}
}
}
testing {
suites {
val test by getting(JvmTestSuite::class) {
useJUnitJupiter(versionCatalog.findVersion("junit").get().requiredVersion)
}
}
}
dependencies {
compileOnly(kotlin("stdlib-jdk8"))
}
java {
withSourcesJar()
withJavadocJar()
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}