Carlos Chacin

Software Engineering Experiences


☕🚢 Maven Build in < 20 lines of yaml 🕟

Posted at September 22, 2021 /

github-actions

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

Create the directory

$ mkdir -p .github/workflows

Create the yaml file

$ touch .github/workflows/maven.yml

Copy this content

name: Maven Build
on:
  push:
    branches:
      - main
jobs:
  build:
    name: "Maven Build"
    runs-on: ubuntu-latest
    steps:
      - name: "Checkout Sources"
        uses: actions/checkout@v2
        with:
          fetch-depth: 2
      - name: "Set up JDK"
        uses: actions/setup-java@v2
        with:
          distribution: "temurin"
          java-version: 11
          cache: "maven"
      - name: "Build with Maven"
        run: mvn verify

Commit and push to Github

$ git add .github && \
  git commit -m "maven build action"

Enjoy your builds

Go to the actions tab for your repository over github.com:

https://github.com/${USER}/${PROJECT}/actions/workflows/maven-build.yml

maven-build