Building and Testing Java with Maven¶
This guide shows you how to create a continuous integration (CI) workflow that builds and tests a Java application with Maven.
Example Workflow¶
name: maven-build-workflow
on: workflow_dispatch
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Maven
uses: stCarolas/setup-maven@v4.5
with:
maven-version: 3.6.0
- name: Maven Build
run: |
mvn clean package
pwd && ls -l
cd target && ls -l
Detailed Explanation¶
- Checkout: Uses
actions/checkoutto get the source code. - Setup Maven: Uses
stCarolas/setup-mavenaction to install a specific version of Maven. Alternatively, you can use the officialactions/setup-javawhich includes Maven support. - Maven Build: Runs
mvn clean packageto build the JAR/WAR file.
📬 DevopsPilot Weekly — Learn DevOps, Cloud & Gen AI the simple way.
👉 Subscribe here