@@ -14,16 +14,14 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
1414import utils.Color
1515import utils.times
1616
17- /* *
18- * Plugin for base build setup of faker modules with kotlin
19- */
20-
17+ /* * Plugin for base build setup of faker modules with kotlin */
2118plugins {
2219 id(" faker-base-conventions" )
2320 java
2421 kotlin(" jvm" )
2522 id(" org.jetbrains.dokka" )
2623 id(" org.jetbrains.kotlinx.binary-compatibility-validator" )
24+ id(" com.diffplug.spotless" )
2725}
2826
2927val lib = project.libs
@@ -38,21 +36,13 @@ dependencies {
3836 testImplementation(lib.bundles.test.kotest)
3937}
4038
41- configure<JavaPluginExtension > {
42- toolchain {
43- languageVersion.set(JavaLanguageVersion .of(8 ))
44- }
45- }
39+ configure<JavaPluginExtension > { toolchain { languageVersion.set(JavaLanguageVersion .of(8 )) } }
4640
4741configure<KotlinJvmProjectExtension > {
48- jvmToolchain {
49- languageVersion.set(JavaLanguageVersion .of(8 ))
50- }
42+ jvmToolchain { languageVersion.set(JavaLanguageVersion .of(8 )) }
5143}
5244
53- tasks.withType<JavaCompile > {
54- options.encoding = " UTF-8"
55- }
45+ tasks.withType<JavaCompile > { options.encoding = " UTF-8" }
5646
5747tasks.withType<Test > {
5848 jvmArgs = jvmArgs?.plus(" -ea" ) ? : listOf (" -ea" )
@@ -62,59 +52,72 @@ tasks.withType<Test> {
6252
6353 testLogging {
6454 // set options for log level LIFECYCLE
65- events = setOf (
66- TestLogEvent .FAILED ,
67- TestLogEvent .SKIPPED ,
68- TestLogEvent .STANDARD_OUT
69- )
55+ events = setOf (TestLogEvent .FAILED , TestLogEvent .SKIPPED , TestLogEvent .STANDARD_OUT )
7056 exceptionFormat = TestExceptionFormat .FULL
7157 showExceptions = true
7258 showCauses = true
7359 showStackTraces = true
7460 // set options for log level DEBUG and INFO
7561 debug {
76- events = setOf (
77- TestLogEvent .STARTED ,
78- TestLogEvent .FAILED ,
79- TestLogEvent .PASSED ,
80- TestLogEvent .SKIPPED ,
81- TestLogEvent .STANDARD_ERROR ,
82- TestLogEvent .STANDARD_OUT
83- )
62+ events =
63+ setOf (
64+ TestLogEvent .STARTED ,
65+ TestLogEvent .FAILED ,
66+ TestLogEvent .PASSED ,
67+ TestLogEvent .SKIPPED ,
68+ TestLogEvent .STANDARD_ERROR ,
69+ TestLogEvent .STANDARD_OUT ,
70+ )
8471 exceptionFormat = TestExceptionFormat .FULL
8572 }
8673 info.events = debug.events
8774 info.exceptionFormat = debug.exceptionFormat
8875
89- afterSuite(KotlinClosure2 ({ desc: TestDescriptor , result: TestResult ->
90- if (desc.parent == null ) { // will match the outermost suite
91- val pass = " ${Color .GREEN }${result.successfulTestCount} passed${Color .NONE } "
92- val fail = " ${Color .RED }${result.failedTestCount} failed${Color .NONE } "
93- val skip = " ${Color .YELLOW }${result.skippedTestCount} skipped${Color .NONE } "
94- val type = when (val r: ResultType = result.resultType) {
95- ResultType .SUCCESS -> " ${Color .GREEN }$r${Color .NONE } "
96- ResultType .FAILURE -> " ${Color .RED }$r${Color .NONE } "
97- ResultType .SKIPPED -> " ${Color .YELLOW }$r${Color .NONE } "
76+ afterSuite(
77+ KotlinClosure2 ({ desc: TestDescriptor , result: TestResult ->
78+ if (desc.parent == null ) { // will match the outermost suite
79+ val pass = " ${Color .GREEN }${result.successfulTestCount} passed${Color .NONE } "
80+ val fail = " ${Color .RED }${result.failedTestCount} failed${Color .NONE } "
81+ val skip = " ${Color .YELLOW }${result.skippedTestCount} skipped${Color .NONE } "
82+ val type =
83+ when (val r: ResultType = result.resultType) {
84+ ResultType .SUCCESS -> " ${Color .GREEN }$r${Color .NONE } "
85+ ResultType .FAILURE -> " ${Color .RED }$r${Color .NONE } "
86+ ResultType .SKIPPED -> " ${Color .YELLOW }$r${Color .NONE } "
87+ }
88+ val output = " Results: $type (${result.testCount} tests, $pass , $fail , $skip )"
89+ val startItem = " | "
90+ val endItem = " |"
91+ val repeatLength = startItem.length + output.length + endItem.length - 36
92+ println (" " )
93+ println (
94+ " \n " +
95+ (" -" * repeatLength) +
96+ " \n " +
97+ startItem +
98+ output +
99+ endItem +
100+ " \n " +
101+ (" -" * repeatLength)
102+ )
98103 }
99- val output = " Results: $type (${result.testCount} tests, $pass , $fail , $skip )"
100- val startItem = " | "
101- val endItem = " |"
102- val repeatLength = startItem.length + output.length + endItem.length - 36
103- println (" " )
104- println (" \n " + (" -" * repeatLength) + " \n " + startItem + output + endItem + " \n " + (" -" * repeatLength))
105- }
106- }))
104+ })
105+ )
107106 }
108107
109- onOutput(KotlinClosure2 ({ _: TestDescriptor , event: TestOutputEvent ->
110- if (event.destination == TestOutputEvent .Destination .StdOut ) {
111- logger.lifecycle(event.message.replace(Regex (""" \s+$""" ), " " ))
112- }
113- }))
108+ onOutput(
109+ KotlinClosure2 ({ _: TestDescriptor , event: TestOutputEvent ->
110+ if (event.destination == TestOutputEvent .Destination .StdOut ) {
111+ logger.lifecycle(event.message.replace(Regex (""" \s+$""" ), " " ))
112+ }
113+ })
114+ )
114115}
115116
116117configurations {
117- create(" integrationImplementation" ) { extendsFrom(configurations.getByName(" testImplementation" )) }
118+ create(" integrationImplementation" ) {
119+ extendsFrom(configurations.getByName(" testImplementation" ))
120+ }
118121 create(" integrationRuntimeOnly" ) {
119122 if (isShadow) {
120123 extendsFrom(
@@ -127,25 +130,23 @@ configurations {
127130 }
128131}
129132
130- // configure sourceSets as extension since it's not available here as `sourceSets` is an extension on `Project`
133+ // configure sourceSets as extension since it's not available here as `sourceSets` is an extension
134+ // on `Project`
131135// https://docs.gradle.org/current/userguide/kotlin_dsl.html#project_extensions_and_conventions
132136configure<SourceSetContainer > {
133137 create(" integration" ) {
134138 resources.srcDir(" src/integration/resources" )
135139 compileClasspath + = main.get().compileClasspath + test.get().compileClasspath
136140 runtimeClasspath + = main.get().runtimeClasspath + test.get().runtimeClasspath
137141 }
138- main {
139- resources {
140- this .srcDir(" build/generated/src/main/resources" )
141- }
142- }
142+ main { resources { this .srcDir(" build/generated/src/main/resources" ) } }
143143}
144144
145- val integrationTest: Test by tasks.creating(Test ::class ) {
146- testClassesDirs = sourceSets[" integration" ].output.classesDirs
147- classpath = sourceSets[" integration" ].runtimeClasspath
148- }
145+ val integrationTest: Test by
146+ tasks.creating(Test ::class ) {
147+ testClassesDirs = sourceSets[" integration" ].output.classesDirs
148+ classpath = sourceSets[" integration" ].runtimeClasspath
149+ }
149150
150151tasks.withType<Jar > {
151152 archiveBaseName.set(fullName)
@@ -161,7 +162,8 @@ tasks.withType<Jar> {
161162 * Cannot change dependencies of dependency configuration ':core:implementation' after it has been included in dependency resolution
162163 * if we try to add more dependencies in the module's build.gradle file directly
163164 */
164- // "Class-Path" to project.configurations.compileClasspath.get().joinToString(" ") { it.name }
165+ // "Class-Path" to project.configurations.compileClasspath.get().joinToString(" ") {
166+ // it.name }
165167 )
166168 )
167169 }
@@ -172,5 +174,12 @@ tasks.withType<DokkaTask>().configureEach {
172174 onlyIf(" Release or snapshot" ) { isRelease.get() || isSnapshot.get() }
173175}
174176
175- apiValidation {
177+ apiValidation {}
178+
179+ spotless {
180+ kotlin { ktfmt().kotlinlangStyle().configure {} }
181+ kotlinGradle {
182+ target(" *.gradle.kts" )
183+ ktfmt().kotlinlangStyle().configure {}
184+ }
176185}
0 commit comments