Skip to content

Commit

Permalink
Swap to ktfmt (googleStyle) for Kotlin code, but keep ktlint fo…
Browse files Browse the repository at this point in the history
…r Gradle scripts (#245)
  • Loading branch information
will-molloy authored Jan 13, 2025
1 parent a37cd10 commit 158acaf
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
[![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)
[![codecov](https://codecov.io/gh/will-molloy/java-template/branch/main/graph/badge.svg)](https://codecov.io/gh/will-molloy/java-template)

template repo for Java/Kotlin projects using Gradle
template repo for Java/Kotlin Gradle projects

## Features

- JDK 21 ([Amazon Corretto](https://aws.amazon.com/corretto/))
- [Gradle 8](https://github.com/gradle/gradle) with Kotlin DSL
- [Gradle 8](https://github.com/gradle/gradle) (Kotlin DSL)
- [GitHub Actions](https://github.com/features/actions) CI/CD
- 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))
- Automatic code formatting via [Spotless](https://github.com/diffplug/spotless)
- Java: [`google-java-format`](https://github.com/google/google-java-format)
- Kotlin: [`ktfmt`](https://github.com/facebook/ktfmt)
- Kotlin Gradle: [`ktlint`](https://github.com/pinterest/ktlint)
- Code style analysis via [Checkstyle](https://github.com/checkstyle/checkstyle)
- Static analysis via [SpotBugs](https://spotbugs.github.io/)
- Unit and integration test support via [JUnit 5](https://junit.org/junit5/) and [TestSets plugin](https://github.com/unbroken-dome/gradle-testsets-plugin)
Expand Down
9 changes: 6 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ allprojects {

apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
// https://github.com/diffplug/spotless/tree/main/plugin-gradle#java
java {
removeUnusedImports()
googleJavaFormat()
trimTrailingWhitespace()
endWithNewline()
}
// https://github.com/diffplug/spotless/tree/main/plugin-gradle#kotlin
kotlin {
ktlint()
ktfmt().googleStyle()
trimTrailingWhitespace()
endWithNewline()
}
Expand All @@ -55,7 +57,7 @@ allprojects {
}
}

// TODO this doesn't work on Kotlin, look into Detekt?
// TODO Kotlin alternative?
apply(plugin = "checkstyle")
configure<CheckstyleExtension> {
toolVersion = "10.12.0"
Expand Down Expand Up @@ -137,7 +139,8 @@ allprojects {
exclude(group = "org.assertj")
exclude(group = "junit")
resolutionStrategy {
force("com.google.guava:guava:${rootProject.libs.versions.guava.get()}") // exclude android version
// exclude android version
force("com.google.guava:guava:${rootProject.libs.versions.guava.get()}")
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions example-java/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
plugins {
alias(libs.plugins.testsets)
}
plugins { alias(libs.plugins.testsets) }

testSets {
create("integrationTest")
}
testSets { create("integrationTest") }
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package com.willmolloy
* @author <a href=https://willmolloy.com>Will Molloy</a>
*/
class HelloWorld {

fun hello(text: String): String {
return "Hello $text!"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package com.willmolloy
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test

/**
* Unit tests for [HelloWorld].
*/
/** Unit tests for [HelloWorld]. */
class HelloWorldTest {

@Test
fun `test hello`() {
assertThat(HelloWorld().hello("world")).isEqualTo("Hello world!")
Expand Down

0 comments on commit 158acaf

Please sign in to comment.