Publish package to the Maven Central Repository #27
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build a Java project with Maven and publish artifact to Maven Central (https://search.maven.org) | |
# | |
# Additional information: | |
# - https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-maven#publishing-packages-to-the-maven-central-repository | |
# - https://blogs.itemis.com/en/github-actions-releasing-artifacts-into-maven-central | |
# - https://itnext.io/publishing-artifacts-to-maven-central-using-github-actions-a-step-by-step-guide-fd65ef075fd4 | |
# - https://github.com/naturalett/maven-hello-world/blob/main/.github/workflows/maven.yml | |
name: Publish package to the Maven Central Repository | |
on: | |
workflow_dispatch: | |
push: | |
tags: [ "*" ] | |
jobs: | |
build: | |
name: Build, release and publish to Maven Central | |
runs-on: ubuntu-latest | |
steps: | |
# Checks out a copy of project's repository. | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
# Shallow clones should be disabled for a better relevancy of analysis | |
fetch-depth: 0 | |
# Sets up the Java JDK, and also configures the Maven `settings.xml` file to add authentication for the | |
# `ossrh` repository using the `OSSRH_USERNAME` and `OSSRH_TOKEN` environment variables. | |
- name: Set up Project | |
uses: actions/setup-java@v4 | |
with: | |
java-version-file: '.java-version' | |
distribution: 'temurin' | |
cache: 'maven' | |
cache-dependency-path: 'pom.yml' | |
# must match the serverId configured for the nexus-staging-maven-plugin in the POM | |
server-id: ossrh | |
server-username: OSSRH_USERNAME | |
server-password: OSSRH_TOKEN | |
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} | |
gpg-passphrase: MAVEN_GPG_PASSPHRASE | |
- name: Cache SonarCloud packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.sonar/cache | |
key: ${{ runner.os }}-sonar | |
restore-keys: ${{ runner.os }}-sonar | |
# Runs the Maven command to publish to the `ossrh` repository. | |
# The `OSSRH_USERNAME` environment variable will be set with the contents of your `OSSRH_USERNAME` secret, | |
# and the `OSSRH_TOKEN` environment variable will be set with the contents of your `OSSRH_TOKEN` secret. | |
- name: Build, analyze and publish package | |
env: | |
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} | |
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} | |
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: ./mvnw --batch-mode deploy org.sonarsource.scanner.maven:sonar-maven-plugin:RELEASE:sonar -Pmaven-central-publishing |