diff --git a/README.md b/README.md index 12998a9..7a6cd56 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/build.gradle.kts b/build.gradle.kts index 9117c35..22c515f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -37,14 +37,16 @@ allprojects { apply(plugin = "com.diffplug.spotless") configure { + // 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() } @@ -55,7 +57,7 @@ allprojects { } } - // TODO this doesn't work on Kotlin, look into Detekt? + // TODO Kotlin alternative? apply(plugin = "checkstyle") configure { toolVersion = "10.12.0" @@ -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()}") } } } diff --git a/example-java/build.gradle.kts b/example-java/build.gradle.kts index 3ff8c1f..dae66ed 100644 --- a/example-java/build.gradle.kts +++ b/example-java/build.gradle.kts @@ -1,7 +1,3 @@ -plugins { - alias(libs.plugins.testsets) -} +plugins { alias(libs.plugins.testsets) } -testSets { - create("integrationTest") -} +testSets { create("integrationTest") } diff --git a/example-kotlin/src/main/kotlin/com/willmolloy/HelloWorld.kt b/example-kotlin/src/main/kotlin/com/willmolloy/HelloWorld.kt index a941572..5a74d96 100644 --- a/example-kotlin/src/main/kotlin/com/willmolloy/HelloWorld.kt +++ b/example-kotlin/src/main/kotlin/com/willmolloy/HelloWorld.kt @@ -6,6 +6,7 @@ package com.willmolloy * @author Will Molloy */ class HelloWorld { + fun hello(text: String): String { return "Hello $text!" } diff --git a/example-kotlin/src/test/kotlin/com/willmolloy/HelloWorldTest.kt b/example-kotlin/src/test/kotlin/com/willmolloy/HelloWorldTest.kt index 01488d0..a510605 100644 --- a/example-kotlin/src/test/kotlin/com/willmolloy/HelloWorldTest.kt +++ b/example-kotlin/src/test/kotlin/com/willmolloy/HelloWorldTest.kt @@ -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!")