Skip to content

Commit 158acaf

Browse files
authored
Swap to ktfmt (googleStyle) for Kotlin code, but keep ktlint for Gradle scripts (#245)
1 parent a37cd10 commit 158acaf

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
[![build](https://github.com/will-molloy/java-template/actions/workflows/build.yml/badge.svg?branch=main&event=push)](https://github.com/will-molloy/java-template/actions/workflows/build.yml)
44
[![codecov](https://codecov.io/gh/will-molloy/java-template/branch/main/graph/badge.svg)](https://codecov.io/gh/will-molloy/java-template)
55

6-
template repo for Java/Kotlin projects using Gradle
6+
template repo for Java/Kotlin Gradle projects
77

88
## Features
99

1010
- JDK 21 ([Amazon Corretto](https://aws.amazon.com/corretto/))
11-
- [Gradle 8](https://github.com/gradle/gradle) with Kotlin DSL
11+
- [Gradle 8](https://github.com/gradle/gradle) (Kotlin DSL)
1212
- [GitHub Actions](https://github.com/features/actions) CI/CD
13-
- Automatic code formatting via [Spotless](https://github.com/diffplug/spotless) ([`google-java-format`](https://github.com/google/google-java-format) and [`ktlint`](https://github.com/pinterest/ktlint))
13+
- Automatic code formatting via [Spotless](https://github.com/diffplug/spotless)
14+
- Java: [`google-java-format`](https://github.com/google/google-java-format)
15+
- Kotlin: [`ktfmt`](https://github.com/facebook/ktfmt)
16+
- Kotlin Gradle: [`ktlint`](https://github.com/pinterest/ktlint)
1417
- Code style analysis via [Checkstyle](https://github.com/checkstyle/checkstyle)
1518
- Static analysis via [SpotBugs](https://spotbugs.github.io/)
1619
- Unit and integration test support via [JUnit 5](https://junit.org/junit5/) and [TestSets plugin](https://github.com/unbroken-dome/gradle-testsets-plugin)

build.gradle.kts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ allprojects {
3737

3838
apply(plugin = "com.diffplug.spotless")
3939
configure<SpotlessExtension> {
40+
// https://github.com/diffplug/spotless/tree/main/plugin-gradle#java
4041
java {
4142
removeUnusedImports()
4243
googleJavaFormat()
4344
trimTrailingWhitespace()
4445
endWithNewline()
4546
}
47+
// https://github.com/diffplug/spotless/tree/main/plugin-gradle#kotlin
4648
kotlin {
47-
ktlint()
49+
ktfmt().googleStyle()
4850
trimTrailingWhitespace()
4951
endWithNewline()
5052
}
@@ -55,7 +57,7 @@ allprojects {
5557
}
5658
}
5759

58-
// TODO this doesn't work on Kotlin, look into Detekt?
60+
// TODO Kotlin alternative?
5961
apply(plugin = "checkstyle")
6062
configure<CheckstyleExtension> {
6163
toolVersion = "10.12.0"
@@ -137,7 +139,8 @@ allprojects {
137139
exclude(group = "org.assertj")
138140
exclude(group = "junit")
139141
resolutionStrategy {
140-
force("com.google.guava:guava:${rootProject.libs.versions.guava.get()}") // exclude android version
142+
// exclude android version
143+
force("com.google.guava:guava:${rootProject.libs.versions.guava.get()}")
141144
}
142145
}
143146
}

example-java/build.gradle.kts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
plugins {
2-
alias(libs.plugins.testsets)
3-
}
1+
plugins { alias(libs.plugins.testsets) }
42

5-
testSets {
6-
create("integrationTest")
7-
}
3+
testSets { create("integrationTest") }

example-kotlin/src/main/kotlin/com/willmolloy/HelloWorld.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package com.willmolloy
66
* @author <a href=https://willmolloy.com>Will Molloy</a>
77
*/
88
class HelloWorld {
9+
910
fun hello(text: String): String {
1011
return "Hello $text!"
1112
}

example-kotlin/src/test/kotlin/com/willmolloy/HelloWorldTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ package com.willmolloy
33
import com.google.common.truth.Truth.assertThat
44
import org.junit.jupiter.api.Test
55

6-
/**
7-
* Unit tests for [HelloWorld].
8-
*/
6+
/** Unit tests for [HelloWorld]. */
97
class HelloWorldTest {
8+
109
@Test
1110
fun `test hello`() {
1211
assertThat(HelloWorld().hello("world")).isEqualTo("Hello world!")

0 commit comments

Comments
 (0)