Skip to content

Commit daf890c

Browse files
author
Marvin Zhang
committed
chore: Refactor Maven build configuration and GitHub Actions workflow
- Moved Maven build plugins into a dedicated 'release' profile in pom.xml for better organization and clarity. - Updated GitHub Actions workflow to use JDK 21 and streamlined the setup for Maven Central publishing. - Removed redundant steps and improved environment variable handling for GPG key management during deployment. - Enhanced the configuration for Maven plugins, ensuring proper artifact signing and source/javadoc attachment during the release process.
1 parent ff78f28 commit daf890c

File tree

2 files changed

+83
-132
lines changed

2 files changed

+83
-132
lines changed

.github/workflows/publish.yml

+12-72
Original file line numberDiff line numberDiff line change
@@ -11,80 +11,20 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v3
1313

14-
- name: Set up JDK 17
15-
uses: actions/setup-java@v3
14+
- name: Set up Maven Central Repository
15+
uses: actions/setup-java@v4
1616
with:
17-
java-version: '17'
17+
java-version: '21'
1818
distribution: 'temurin'
19-
server-id: ossrh # Maven Central settings server id
20-
server-username: ${{ secrets.OSSRH_USERNAME }}
21-
server-password: ${{ secrets.OSSRH_PASSWORD }}
19+
server-id: central
20+
server-username: MAVEN_USERNAME
21+
server-password: MAVEN_PASSWORD
2222
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
23-
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
23+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
2424

25-
- name: Cache Maven dependencies
26-
uses: actions/cache@v3
27-
with:
28-
path: ~/.m2/repository
29-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
30-
restore-keys: |
31-
${{ runner.os }}-m2-
32-
33-
- name: Setup Maven settings
34-
run: |
35-
mkdir -p ~/.m2
36-
echo "<settings>
37-
<servers>
38-
<server>
39-
<id>ossrh</id>
40-
<username>${{ secrets.OSSRH_USERNAME }}</username>
41-
<password>${{ secrets.OSSRH_PASSWORD }}</password>
42-
</server>
43-
<server>
44-
<id>github</id>
45-
<username>${{ secrets.GITHUB_ACTOR }}</username>
46-
<password>${{ secrets.GITHUB_TOKEN }}</password>
47-
</server>
48-
</servers>
49-
<profiles>
50-
<profile>
51-
<id>ossrh</id>
52-
<repositories>
53-
<repository>
54-
<id>ossrh</id>
55-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
56-
</repository>
57-
</repositories>
58-
</profile>
59-
<profile>
60-
<id>github</id>
61-
<repositories>
62-
<repository>
63-
<id>github</id>
64-
<url>https://maven.pkg.github.com/crawlab-team/crawlab-java-sdk</url>
65-
</repository>
66-
</repositories>
67-
</profile>
68-
</profiles>
69-
<activeProfiles>
70-
<activeProfile>ossrh</activeProfile>
71-
<activeProfile>github</activeProfile>
72-
</activeProfiles>
73-
</settings>" > ~/.m2/settings.xml
74-
75-
- name: Import GPG key
76-
run: |
77-
echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --batch --import
25+
- name: Publish package
26+
run: mvn -P release --batch-mode deploy
7827
env:
79-
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
80-
81-
- name: Reload gpg-agent
82-
run: gpg-connect-agent reloadagent /bye
83-
84-
- name: Build and Test
85-
run: mvn clean test
86-
87-
- name: Build and Publish to Maven Central and GitHub Packages
88-
run: |
89-
export GPG_TTY=$(tty)
90-
mvn clean deploy -P ossrh,github -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }}
28+
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
29+
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
30+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

pom.xml

+71-60
Original file line numberDiff line numberDiff line change
@@ -49,64 +49,75 @@
4949
</dependency>
5050
</dependencies>
5151

52-
<build>
53-
<plugins>
54-
<!-- Javadoc plugin -->
55-
<plugin>
56-
<groupId>org.apache.maven.plugins</groupId>
57-
<artifactId>maven-javadoc-plugin</artifactId>
58-
<version>3.3.1</version>
59-
<executions>
60-
<execution>
61-
<goals>
62-
<goal>jar</goal>
63-
</goals>
64-
</execution>
65-
</executions>
66-
</plugin>
67-
68-
<!-- Source plugin -->
69-
<plugin>
70-
<groupId>org.apache.maven.plugins</groupId>
71-
<artifactId>maven-source-plugin</artifactId>
72-
<version>3.2.1</version>
73-
<executions>
74-
<execution>
75-
<goals>
76-
<goal>jar</goal>
77-
</goals>
78-
</execution>
79-
</executions>
80-
</plugin>
81-
82-
<!-- GPG plugin -->
83-
<plugin>
84-
<groupId>org.apache.maven.plugins</groupId>
85-
<artifactId>maven-gpg-plugin</artifactId>
86-
<version>1.6</version>
87-
<executions>
88-
<execution>
89-
<id>sign-artifacts</id>
90-
<phase>verify</phase>
91-
<goals>
92-
<goal>sign</goal>
93-
</goals>
94-
</execution>
95-
</executions>
96-
</plugin>
97-
98-
<!-- Central publishing plugin -->
99-
<plugin>
100-
<groupId>org.sonatype.central</groupId>
101-
<artifactId>central-publishing-maven-plugin</artifactId>
102-
<version>0.6.0</version>
103-
<extensions>true</extensions>
104-
<configuration>
105-
<publishingServerId>central</publishingServerId>
106-
<autoPublish>true</autoPublish>
107-
<waitUntil>published</waitUntil>
108-
</configuration>
109-
</plugin>
110-
</plugins>
111-
</build>
52+
<profiles>
53+
<profile>
54+
<id>release</id>
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>org.sonatype.central</groupId>
59+
<artifactId>central-publishing-maven-plugin</artifactId>
60+
<version>0.6.0</version>
61+
<extensions>true</extensions>
62+
<configuration>
63+
<publishingServerId>central</publishingServerId>
64+
<autoPublish>true</autoPublish>
65+
<waitUntil>published</waitUntil>
66+
</configuration>
67+
</plugin>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-source-plugin</artifactId>
71+
<version>3.2.1</version>
72+
<executions>
73+
<execution>
74+
<id>attach-sources</id>
75+
<phase>verify</phase>
76+
<goals>
77+
<goal>jar-no-fork</goal>
78+
</goals>
79+
</execution>
80+
</executions>
81+
</plugin>
82+
<plugin>
83+
<groupId>org.apache.maven.plugins</groupId>
84+
<artifactId>maven-javadoc-plugin</artifactId>
85+
<version>3.3.1</version>
86+
<executions>
87+
<execution>
88+
<id>attach-javadoc</id>
89+
<goals>
90+
<goal>jar</goal>
91+
</goals>
92+
</execution>
93+
</executions>
94+
<configuration>
95+
<stylesheet>java</stylesheet>
96+
<doclint>none</doclint>
97+
</configuration>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-gpg-plugin</artifactId>
102+
<version>1.6</version>
103+
<executions>
104+
<execution>
105+
<id>sign-artifacts</id>
106+
<phase>verify</phase>
107+
<goals>
108+
<goal>sign</goal>
109+
</goals>
110+
</execution>
111+
</executions>
112+
<configuration>
113+
<gpgArguments>
114+
<arg>--pinentry-mode</arg>
115+
<arg>loopback</arg>
116+
</gpgArguments>
117+
</configuration>
118+
</plugin>
119+
</plugins>
120+
</build>
121+
</profile>
122+
</profiles>
112123
</project>

0 commit comments

Comments
 (0)