Skip to content

Commit 0f3178d

Browse files
author
Marvin Zhang
committed
chore: Add distribution management and enhance GitHub Actions workflow for Maven Central publishing
- Introduced distribution management section in pom.xml for centralized repository configuration. - Added central-publishing-maven-plugin to both release and snapshot profiles for automated publishing to Maven Central. - Updated GitHub Actions workflow to differentiate between release and snapshot profiles, improving deployment flexibility. - Enhanced setup steps to dynamically set the Maven profile based on the event type (release or push).
1 parent e92309b commit 0f3178d

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

.github/workflows/publish.yml

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1-
name: Publish to Maven Central and GitHub Packages
1+
name: Publish to Maven Central
22

33
on:
44
push:
55
branches:
66
- main
7+
pull_request:
8+
branches:
9+
- main
10+
release:
11+
types: [published]
712

813
jobs:
914
publish:
1015
runs-on: ubuntu-latest
1116
steps:
1217
- uses: actions/checkout@v3
1318

19+
- name: Setup
20+
id: setup
21+
run: |
22+
# set PROFILE according to the event
23+
if [ -n "${{ github.event.release }}" ]; then
24+
echo "PROFILE=release" >> $GITHUB_ENV
25+
else
26+
echo "PROFILE=snapshot" >> $GITHUB_ENV
27+
fi
28+
echo "PROFILE: ${PROFILE}"
29+
1430
- name: Set up Maven Central Repository
31+
id: setup-maven
1532
uses: actions/setup-java@v4
1633
with:
1734
java-version: '17'
@@ -23,7 +40,8 @@ jobs:
2340
gpg-passphrase: MAVEN_GPG_PASSPHRASE
2441

2542
- name: Publish package
26-
run: mvn -P release --batch-mode deploy
43+
run: |
44+
mvn -P ${{ env.PROFILE }} --batch-mode deploy
2745
env:
2846
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
2947
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}

pom.xml

+35
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@
3030
<url>https://github.com/crawlab-team/crawlab-java-sdk</url>
3131
</scm>
3232

33+
<distributionManagement>
34+
<repository>
35+
<id>central</id>
36+
<name>Central Repository</name>
37+
<url>https://central.sonatype.com/content/repositories/releases</url>
38+
</repository>
39+
<snapshotRepository>
40+
<id>central</id>
41+
<name>Central Snapshots</name>
42+
<url>https://central.sonatype.com/content/repositories/snapshots</url>
43+
</snapshotRepository>
44+
</distributionManagement>
45+
3346
<properties>
3447
<maven.compiler.source>17</maven.compiler.source>
3548
<maven.compiler.target>17</maven.compiler.target>
@@ -55,6 +68,17 @@
5568
<id>release</id>
5669
<build>
5770
<plugins>
71+
<plugin>
72+
<groupId>org.sonatype.central</groupId>
73+
<artifactId>central-publishing-maven-plugin</artifactId>
74+
<version>0.6.0</version>
75+
<extensions>true</extensions>
76+
<configuration>
77+
<publishingServerId>central</publishingServerId>
78+
<autoPublish>true</autoPublish>
79+
<waitUntil>published</waitUntil>
80+
</configuration>
81+
</plugin>
5882
<plugin>
5983
<groupId>org.apache.maven.plugins</groupId>
6084
<artifactId>maven-source-plugin</artifactId>
@@ -118,6 +142,17 @@
118142
<id>snapshot</id>
119143
<build>
120144
<plugins>
145+
<plugin>
146+
<groupId>org.sonatype.central</groupId>
147+
<artifactId>central-publishing-maven-plugin</artifactId>
148+
<version>0.6.0</version>
149+
<extensions>true</extensions>
150+
<configuration>
151+
<publishingServerId>central</publishingServerId>
152+
<autoPublish>true</autoPublish>
153+
<waitUntil>published</waitUntil>
154+
</configuration>
155+
</plugin>
121156
<plugin>
122157
<groupId>org.apache.maven.plugins</groupId>
123158
<artifactId>maven-source-plugin</artifactId>

0 commit comments

Comments
 (0)