How to Set Up CI for Kotlin With GitHub Actions
Kotlin projects build with Gradle, so the JDK plus setup-gradle caching and ktlintCheck cover lint and test.
Provide a JDK with actions/setup-java, add gradle/actions/setup-gradle for caching, then run ./gradlew ktlintCheck test (assuming the ktlint Gradle plugin) via the wrapper.
Steps
- Check out the code.
- Run
actions/setup-javafor the JDK. - Add
gradle/actions/setup-gradleto cache the build. - Run
./gradlew ktlintCheck test.
Workflow
.github/workflows/ci.yml
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- uses: gradle/actions/setup-gradle@v4
- run: ./gradlew ktlintCheck test --no-daemonGotchas
ktlintCheckexists only if the ktlint Gradle plugin is applied; use detekt instead if that is your linter.- Kotlin compilation is JDK-sensitive; match the JDK to your Gradle toolchain setting.
Related guides
How to Set Up CI for Java (Gradle) With GitHub ActionsSet up GitHub Actions CI for a Gradle project: setup-java provides the JDK, gradle/actions/setup-gradle cache…
How to Set Up CI for a Swift Package With GitHub ActionsSet up GitHub Actions CI for a Swift Package Manager library: run on macOS, cache the .build directory, build…