Basic Github action for Kotlin (Gradle): build and test

I recently started working with Kotlin. And unlike in my Rust and Scala projects, Github did not suggest a CI workflow for me.
You can use a bog-standard Java workflow and just add two commands:
chmod +x gradlew
Make the gradle wrapper executable (assuming you use gradle wrapper)
./gradlew test --no-daemon
builds the project and runs tests (if you have any)
Here is the workflow (goes into .github/workflows/ci.yml
:
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run tests
run: ./gradlew test --no-daemon
If you want some more info in your test output, you can add this to your build.gradle.kts
as a top level definition:
tasks.test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
showStandardStreams = true
}
}
Personally I'm using kotest, and my dev requirements look like this:
dependencies {
// other stuff
testImplementation(kotlin("test"))
testImplementation("io.kotest:kotest-runner-junit5:5.8.0")
testImplementation("io.kotest:kotest-assertions-core:5.8.0")
}