Skip to content

Publish package to the Maven Central Repository #28

Publish package to the Maven Central Repository

Publish package to the Maven Central Repository #28

Workflow file for this run

name: Publish package to the Maven Central Repository
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Configure Maven settings.xml
run: |
mkdir -p /home/runner/.m2
cat > /home/runner/.m2/settings.xml <<EOL
<settings>
<servers>
<server>
<id>central-releases-staging</id>
<username>${{ secrets.OSS_SONATYPE_USERNAME }}</username>
<password>${{ secrets.OSS_SONATYPE_PASSWORD }}</password>
</server>
</servers>
<profiles>
<profile>
<id>ossrh</id>
<properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>${{ secrets.GPG_SIGNING_PASSPHRASE }}</gpg.passphrase>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>ossrh</activeProfile>
</activeProfiles>
</settings>
EOL
- name: Import GPG key
env:
GPG_TTY: $(tty)
run: |
echo "${{ secrets.GPG_SIGNING_PRIVATE_KEY }}" | gpg --batch --import
echo "use-agent" >> ~/.gnupg/gpg.conf
echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
gpg --batch --yes --pinentry-mode loopback --passphrase $GPG_SIGNING_PASSPHRASE --list-keys
- name: Build and publish to Maven Central
env:
GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_PASSPHRASE }}
MAVEN_USERNAME: ${{ secrets.OSS_SONATYPE_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.OSS_SONATYPE_PASSWORD }}
MAVEN_OPTS: --add-opens java.base/java.util=ALL-UNNAMED
run:
mvn clean deploy -PmavenCentral -DskipTests --settings /home/runner/.m2/settings.xml -Dgpg.passphrase=${{ secrets.GPG_SIGNING_PASSPHRASE }}