Skip to content

Publish to Maven Central #1

Publish to Maven Central

Publish to Maven Central #1

Workflow file for this run

name: Publish to Maven Central
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Version to publish (e.g. 2.20.0-rc1). Leave empty for a timestamped SNAPSHOT.'
required: false
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Determine version
id: version
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
# Strip leading 'v' if present (e.g. v2.20.0 -> 2.20.0)
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
elif [[ -n "${{ github.event.inputs.version }}" ]]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION="0.0.0-$(date -u +%Y%m%d%H%M%S)-SNAPSHOT"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Publishing version: $VERSION"
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'
cache: 'maven'
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Publish to Maven Central
run: mvn --batch-mode clean deploy -Drevision=${{ steps.version.outputs.version }}
env:
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}