Skip to content
Latchkey

GitHub Actions Workflow Template for Java (Maven)

A complete, caching-enabled GitHub Actions workflow for Java (Maven). Drop it in .github/workflows/ci.yml and adjust.

This template builds and tests a Java (Maven) project with dependency caching and sensible defaults. It uses setup-java Maven caching.

The workflow

.github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: '21'
          cache: maven
      - run: mvn -B verify

What it does

  • Caches ~/.m2
  • Builds and tests with Maven

Run it cheaper

Change runs-on: ubuntu-latest to a Latchkey label to run this same workflow at roughly 69% lower per-minute cost, with self-healing for transient failures.

Related guides

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