Skip to content

Commit aa2e4a7

Browse files
committed
add maven-publish github action
1 parent 4e9842d commit aa2e4a7

File tree

2 files changed

+62
-6
lines changed

2 files changed

+62
-6
lines changed

.github/workflows/maven-publish.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Publish to Maven Central
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
build-and-publish:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
# 检出代码
13+
- name: Checkout Code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
# 设置所需的Java版本
19+
- name: Set up Java
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: '8'
23+
distribution: 'temurin'
24+
server-id: central
25+
server-username: MAVEN_USERNAME
26+
server-password: MAVEN_PASSWORD
27+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
28+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
29+
cache: maven
30+
31+
- name: Verify GPG keys
32+
run: |
33+
echo "Available GPG Keys:"
34+
gpg --list-secret-keys --keyid-format LONG
35+
36+
- name: Generate version && Set version
37+
id: set_version
38+
run: |
39+
git describe --tags 2>/dev/null || echo "no tag"
40+
TIMESTAMP=$(date +'%Y%m%d.%H%M%S')
41+
GIT_DESCRIBE=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.0.1")
42+
VERSION="${GIT_DESCRIBE}-${TIMESTAMP}"
43+
echo "Generated version: $VERSION"
44+
mvn versions:set -DnewVersion=$VERSION --no-transfer-progress
45+
env:
46+
TZ: Asia/Shanghai
47+
48+
- name: Publish to Maven Central
49+
run: |
50+
mvn clean deploy -P release \
51+
-Dmaven.test.skip=true \
52+
-Dgpg.args="--batch --yes --pinentry-mode loopback" \
53+
--no-transfer-progress
54+
env:
55+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
56+
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
57+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

pom.xml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,13 @@
172172

173173
<plugins>
174174
<plugin>
175-
<groupId>org.sonatype.plugins</groupId>
176-
<artifactId>nexus-staging-maven-plugin</artifactId>
177-
<version>1.6.3</version>
175+
<groupId>org.sonatype.central</groupId>
176+
<artifactId>central-publishing-maven-plugin</artifactId>
177+
<version>0.7.0</version>
178178
<extensions>true</extensions>
179179
<configuration>
180-
<serverId>ossrh</serverId>
181-
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
182-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
180+
<publishingServerId>central</publishingServerId>
181+
<autoPublish>true</autoPublish>
183182
</configuration>
184183
</plugin>
185184
<plugin>

0 commit comments

Comments
 (0)