1+ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2+ import org.gradle.api.tasks.testing.logging.TestLogEvent
3+
14plugins {
25 // Apply the java-library plugin for API and implementation separation.
36 id ' java-library'
@@ -9,11 +12,85 @@ java {
912 targetCompatibility = JavaVersion . VERSION_17
1013}
1114
12- tasks. withType(JavaCompile ) {
15+ tasks. withType(JavaCompile ). configureEach {
1316 // Configure string concat to always inline compile
1417 options. compilerArgs. add ' -XDstringConcat=inline'
1518}
1619
20+ project. ext {
21+ runningTestDescriptions = [] as Set
22+ }
23+
24+ tasks. withType(Test ). configureEach {
25+
26+ testLogging {
27+ // set options for log level LIFECYCLE
28+ events TestLogEvent . FAILED ,
29+ TestLogEvent . PASSED ,
30+ TestLogEvent . SKIPPED ,
31+ TestLogEvent . STANDARD_OUT
32+ exceptionFormat TestExceptionFormat . FULL
33+ showExceptions true
34+ showCauses true
35+ showStackTraces true
36+
37+ // set options for log level DEBUG and INFO
38+ debug {
39+ events TestLogEvent . STARTED ,
40+ TestLogEvent . FAILED ,
41+ TestLogEvent . PASSED ,
42+ TestLogEvent . SKIPPED ,
43+ TestLogEvent . STANDARD_ERROR ,
44+ TestLogEvent . STANDARD_OUT
45+ exceptionFormat TestExceptionFormat . FULL
46+ }
47+ info. events = debug. events
48+ info. exceptionFormat = debug. exceptionFormat
49+
50+ beforeTest { desc ->
51+ project. ext. runningTestDescriptions. add(desc. displayName)
52+ }
53+
54+ afterTest { desc , result ->
55+ project. ext. runningTestDescriptions. remove(desc. displayName )
56+ }
57+
58+ afterSuite { desc , result ->
59+ if (! desc. parent) { // will match the outermost suite
60+ def name = desc. name
61+ def idx = name. indexOf(" :" )
62+ if (idx >= 0 ) {
63+ name = name. substring(idx)
64+ }
65+
66+ def rows = [
67+ " Results for ${ name} - ${ result.resultType} (${ result.testCount} tests, ${ result.successfulTestCount} passed, ${ result.failedTestCount} failed, ${ result.skippedTestCount} skipped)"
68+ ]
69+ def running = project. ext. runningTestDescriptions
70+ if (! running. isEmpty()) {
71+ rows. add(" Interrupted tests: ${ running} " )
72+ }
73+ def maxContentLen = rows. stream()
74+ .map { it. length() }
75+ .max(Comparator . naturalOrder())
76+ .orElse(0 )
77+ def startItem = ' │ ' , endItem = ' │'
78+ def repeatLength = startItem. length() + maxContentLen + endItem. length() - 2
79+
80+ def printRow = { String row ->
81+ println (startItem + row + (' ' * (maxContentLen - row. length())) + endItem)
82+ }
83+
84+ println (' \n ┌' + (' ─' * repeatLength) + ' ┐' )
85+ for (row in rows) {
86+ printRow row
87+ }
88+ println (' └' + (' ─' * repeatLength) + ' ┘\n ' )
89+ }
90+ }
91+ }
92+ }
93+
1794tasks. named(' jar' ) {
1895 manifest {
1996 attributes(
0 commit comments