forked from serpro69/kotlin-faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
235 lines (203 loc) · 7.48 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
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import io.qameta.allure.gradle.task.AllureReport
import io.qameta.allure.gradle.task.AllureServe
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.gradle.api.tasks.testing.TestResult.ResultType
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
plugins {
kotlin("jvm") version "1.8.10" apply false
id("com.adarshr.test-logger") version "2.0.0" apply false
id("com.github.ben-manes.versions") version "0.28.0" apply false
id("io.qameta.allure") version "2.8.1"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("com.github.johnrengelman.shadow") version "6.1.0" apply false
}
repositories {
mavenCentral()
}
group = "io.github.serpro69"
subprojects {
group = parent?.group?.toString() ?: "io.github.serpro69"
version = rootProject.version
repositories {
mavenCentral()
}
apply {
plugin("java")
plugin("org.jetbrains.kotlin.jvm")
plugin("com.adarshr.test-logger")
plugin("com.github.ben-manes.versions")
plugin("io.qameta.allure")
plugin("com.github.johnrengelman.shadow")
}
dependencies {
val implementation by configurations
val testRuntimeOnly by configurations
val testImplementation by configurations
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation("com.github.mifmif:generex:1.0.2")
testImplementation("io.kotest:kotest-runner-junit5:5.5.5")
testImplementation("io.kotest:kotest-runner-junit5-jvm:5.5.5")
testImplementation("io.kotest:kotest-assertions-core-jvm:5.5.5")
testImplementation("io.kotest:kotest-property-jvm:5.5.5")
testImplementation("io.kotest.extensions:kotest-extensions-allure:1.2.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
testRuntimeOnly("ch.qos.logback:logback-core:1.3.4") {
version {
strictly("1.3.4") // last stable for java 8
}
}
testRuntimeOnly("ch.qos.logback:logback-classic:1.3.4") {
version {
strictly("1.3.4") // last stable for java 8
}
}
testRuntimeOnly("org.codehaus.groovy:groovy:3.0.16")
}
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.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.PASSED,
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.toUpperCase().contains(it) }
val regex = "^[0-9,.v-]+(-r|-jre)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}
rejectVersionIf {
isNonStable(candidate.version)
}
}
allure {
version = "2.8.1"
aspectjweaver = false
aspectjVersion = "1.9.19"
autoconfigure = true
// TODO check if fixed in future versions of allure
configuration = "testRuntimeOnly" // defaults to 'testCompile' which is incompatible with gradle 7.x
allureJavaVersion = "2.21.0"
useJUnit5 {
version = "2.21.0"
}
}
}
rootProject.allure {
version = "2.8.1"
}
val allureAggregatedReport by tasks.creating(AllureReport::class) {
doFirst {
val results = mutableListOf<File>()
subprojects.stream().forEach {
it.allure.resultsDir?.let { dir ->
results.add(dir)
}
}
resultsDirs = results
}
}
val allureAggregatedServe by tasks.creating(AllureServe::class) {
doFirst {
val results = mutableListOf<File>()
subprojects.stream().forEach {
it.allure.resultsDir?.let { dir ->
results.add(dir)
}
}
resultsDirs = results
}
}
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
}
}