Note: GitHub-hosted runners are not currently supported on GitHub Enterprise Server. You can see more information about planned future support on the GitHub public roadmap.
Introduction
This guide shows you how to create a workflow that performs continuous integration (CI) for your Java project using the Maven software project management tool. The workflow you create will allow you to see when commits to a pull request cause build or test failures against your default branch; this approach can help ensure that your code is always healthy. You can extend your CI workflow to upload artifacts from a workflow run.
GitHub-hosted runners have a tools cache with pre-installed software, which includes Java Development Kits (JDKs) and Maven. For a list of software and the pre-installed versions for JDK and Maven, see "About GitHub-hosted runners".
Prerequisites
You should be familiar with YAML and the syntax for GitHub Actions. For more information, see:
We recommend that you have a basic understanding of Java and the Maven framework. For more information, see the Maven Getting Started Guide in the Maven documentation.
Using self-hosted runners on GitHub Enterprise Server
When using setup actions (such as actions/setup-LANGUAGE) on GitHub Enterprise Server with self-hosted runners, you might need to set up the tools cache on runners that do not have internet access. For more information, see "Setting up the tool cache on self-hosted runners without internet access."
Using the Maven starter workflow
GitHub provides a Maven starter workflow that will work for most Maven-based Java projects. For more information, see the Maven starter workflow.
To get started quickly, you can choose the preconfigured Maven starter workflow when you create a new workflow. For more information, see the "Quickstart for GitHub Actions."
You can also add this workflow manually by creating a new file in the .github/workflows directory of your repository.
name: Java CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Maven
run: mvn --batch-mode --update-snapshots package
This workflow performs the following steps:
- The
checkoutstep downloads a copy of your repository on the runner. - The
setup-javastep configures the Eclipse Temurin (Java) 17 JDK by Eclipse Adoptium. - The "Build with Maven" step runs the Maven
packagetarget in non-interactive mode to ensure that your code builds, tests pass, and a package can be created.
The default starter workflows are excellent starting points when creating your build and test workflow, and you can customize the starter workflow to suit your project’s needs.
Running on a different operating system
The starter workflow configures jobs to run on Linux, using the GitHub-hosted ubuntu-latest runners. You can change the runs-on key to run your jobs on a different operating system. For example, you can use the GitHub-hosted Windows runners.
runs-on: windows-latest
Or, you can run on the GitHub-hosted macOS runners.
runs-on: macos-latest
You can also run jobs in Docker containers, or you can provide a self-hosted runner that runs on your own infrastructure. For more information, see "Workflow syntax for GitHub Actions."