Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap to ktfmt (googleStyle) for Kotlin code, but keep ktlint for Gradle scripts #245

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ktlint removes this space... but not always ???

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
Loading