Skip to content

Commit

Permalink
github action mvn deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
ezerozen committed Apr 30, 2024
1 parent e5c3646 commit c084ce8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 61 deletions.
58 changes: 31 additions & 27 deletions .github/workflows/maven-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
name: Publish package to the Maven Central Repository

on:
release:
types: [created]
types: [published]

jobs:
publish:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
fetch-tags: true
- name: Import GPG signing key
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.MAVEN_SIGNING_KEY }}
passphrase: ${{ secrets.MAVEN_SIGNING_KEY_PASSPHRASE }}
- name: Install JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
server-id: ossrh
server-username: MVN_CENTRAL_USERNAME
server-password: MVN_CENTRAL_PASSWORD
- name: Release to Maven repo
run: |
mvn -P release -Dmaven.test.skip -Dgpg.keyname=${{ secrets.GPG_KEY_NAME }} -Dgpg.passphrase=${{ secrets.MAVEN_SIGNING_KEY_PASSPHRASE }} \
-Drevision=${{ github.event.release.tag_name }} deploy
env:
MVN_CENTRAL_USERNAME: ${{ secrets.MVN_CENTRAL_USERNAME }}
MVN_CENTRAL_PASSWORD: ${{ secrets.MVN_CENTRAL_PASSWORD }}
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'

- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Set up Apache Maven Central
uses: actions/setup-java@v4
with: # running setup-java again overwrites the settings.xml
distribution: 'temurin'
java-version: '11'
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
server-username: MAVEN_USERNAME # env variable for username in deploy
server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy
gpg-private-key: ${{ secrets.MAVEN_SIGNING_KEY }} # Value of the GPG private key to import
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase

- name: Publish to Apache Maven Central
run: mvn deploy
env:
MAVEN_USERNAME: ${{ secrets.MVN_CENTRAL_USERNAME}}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MVN_CENTRAL_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_SIGNING_KEY_PASSPHRASE }}
38 changes: 4 additions & 34 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
</developers>

<distributionManagement>
<snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<name>Central Repository OSSRH</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<build>
Expand Down Expand Up @@ -185,13 +186,6 @@
<goals>
<goal>sign</goal>
</goals>
<configuration>
<!-- Prevent gpg from using pinentry programs -->
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
Expand Down Expand Up @@ -262,30 +256,6 @@
</plugins>
</build>

<profiles>
<profile>
<id>sign-artifacts</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<dependencies>
<dependency>
<groupId>org.json</groupId>
Expand Down

0 comments on commit c084ce8

Please sign in to comment.