Skip to content
Latchkey

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-java for the JDK.
  • Add gradle/actions/setup-gradle to 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-daemon

Gotchas

  • ktlintCheck exists 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

Run this faster and cheaper on Latchkey managed runners. Start free →