forked from serpro69/kotlin-faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
176 lines (151 loc) · 5.72 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
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import io.github.serpro69.semverkt.gradle.plugin.tasks.TagTask
import org.gradle.api.tasks.testing.TestResult.ResultType
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
plugins {
// NB! some versions are on the classpath from dependency declared in buildSrc/build.gradle.kts
kotlin("jvm") apply false
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
id("io.github.serpro69.semantic-versioning") apply false
id("com.github.ben-manes.versions") version "0.51.0" apply false
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.15.0-Beta.1"
}
group = "io.github.serpro69"
val lib = project.libs
subprojects {
group = rootProject.group.toString()
apply {
plugin("com.github.ben-manes.versions")
}
// don't apply the rest to bom subproject
if ([email protected] == "bom") return@subprojects
apply {
plugin("java")
plugin("org.jetbrains.kotlin.jvm")
}
dependencies {
val implementation by configurations
val testImplementation by configurations
val testRuntimeOnly by configurations
// common-for-all dependencies go here
implementation(platform(lib.kotlin.bom))
implementation(lib.bundles.kotlin)
testImplementation(lib.bundles.test.kotest)
}
configure<JavaPluginExtension> {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
}
configure<KotlinJvmProjectExtension> {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks.withType<Test> {
@Suppress("SimpleRedundantLet", "UNNECESSARY_SAFE_CALL")
jvmArgs?.let { it.plus("-ea") }
useJUnitPlatform()
maxParallelForks = 1
testLogging {
// set options for log level LIFECYCLE
events = setOf(
TestLogEvent.FAILED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_OUT
)
exceptionFormat = TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
// set options for log level DEBUG and INFO
debug {
events = setOf(
TestLogEvent.STARTED,
TestLogEvent.FAILED,
TestLogEvent.PASSED,
TestLogEvent.SKIPPED,
TestLogEvent.STANDARD_ERROR,
TestLogEvent.STANDARD_OUT
)
exceptionFormat = TestExceptionFormat.FULL
}
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat
afterSuite(KotlinClosure2({ desc: TestDescriptor, result: TestResult ->
if (desc.parent == null) { // will match the outermost suite
val pass = "${Color.GREEN}${result.successfulTestCount} passed${Color.NONE}"
val fail = "${Color.RED}${result.failedTestCount} failed${Color.NONE}"
val skip = "${Color.YELLOW}${result.skippedTestCount} skipped${Color.NONE}"
val type = when (val r: ResultType = result.resultType) {
ResultType.SUCCESS -> "${Color.GREEN}$r${Color.NONE}"
ResultType.FAILURE -> "${Color.RED}$r${Color.NONE}"
ResultType.SKIPPED -> "${Color.YELLOW}$r${Color.NONE}"
}
val output = "Results: $type (${result.testCount} tests, $pass, $fail, $skip)"
val startItem = "| "
val endItem = " |"
val repeatLength = startItem.length + output.length + endItem.length - 36
println("")
println("\n" + ("-" * repeatLength) + "\n" + startItem + output + endItem + "\n" + ("-" * repeatLength))
}
}))
}
onOutput(KotlinClosure2({ _: TestDescriptor, event: TestOutputEvent ->
if (event.destination == TestOutputEvent.Destination.StdOut) {
logger.lifecycle(event.message.replace(Regex("""\s+$"""), ""))
}
}))
}
tasks.withType<DependencyUpdatesTask> {
fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r|-jre)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}
rejectVersionIf {
isNonStable(candidate.version)
}
}
}
nexusPublishing {
repositories {
sonatype {
stagingProfileId.set(properties["stagingProfileId"]?.toString())
}
}
}
operator fun String.times(x: Int): String {
return List(x) { this }.joinToString("")
}
internal enum class Color(ansiCode: Int) {
NONE(0),
BLACK(30),
RED(31),
GREEN(32),
YELLOW(33),
BLUE(34),
PURPLE(35),
CYAN(36),
WHITE(37);
private val ansiString: String = "\u001B[${ansiCode}m"
override fun toString(): String {
return ansiString
}
}
// Run :tag only after we've published artifacts to sonatype
tasks.withType<TagTask>().configureEach {
// don't apply when "dryRun"
findProperty("dryRun") ?: run {
dependsOn("closeSonatypeStagingRepository")
}
}
apiValidation {
ignoredProjects += listOf("bom", "cli-bot", "docs", "test")
}