Skip to content

Commit ceb12d7

Browse files
committed
Adjust release process for new Maven Central publishing
Signed-off-by: nscuro <[email protected]>
1 parent d6dd3a9 commit ceb12d7

File tree

2 files changed

+56
-70
lines changed

2 files changed

+56
-70
lines changed

.github/workflows/release.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ jobs:
2727
with:
2828
java-version: '8'
2929
distribution: 'temurin'
30-
server-id: ossrh
31-
server-username: MAVEN_USERNAME
32-
server-password: MAVEN_PASSWORD
30+
server-id: central
31+
server-username: MAVEN_CENTRAL_USERNAME
32+
server-password: MAVEN_CENTRAL_PASSWORD
3333
# Export the gpg private key using the following command and add the contents of that file to the GitHub secret
3434
# gpg --armor --export-secret-keys <key_id> > gpg_key.asc
3535
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
@@ -39,27 +39,23 @@ jobs:
3939
run: |
4040
git config --global user.email "[email protected]"
4141
git config --global user.name "CycloneDX Automation"
42-
git config --global credential.helper 'store --file ~/.git-credentials'
43-
echo "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com" > ~/.git-credentials
4442
4543
- name: Set Maven options
4644
id: maven_options
4745
run: |
4846
# Set the Maven options based on the 'dry_run' input
4947
if ${{ github.event.inputs.dry_run }}; then
50-
echo "options=release:prepare -DdryRun=true -Prelease" >> $GITHUB_ENV
48+
echo "options=release:prepare -DdryRun=true" >> $GITHUB_ENV
5149
else
52-
echo "options=release:clean release:prepare release:perform -Prelease" >> $GITHUB_ENV
50+
echo "options=release:clean release:prepare release:perform" >> $GITHUB_ENV
5351
fi
5452
5553
- name: Run Maven command
56-
# This requires the connection and developerConnection elements in the scm section of the pom
57-
# to be set to "scm:git:https:...." thus preventing the release plugin from using SSH.
5854
run: |
5955
mvn -B ${{ env.options }}
6056
env:
61-
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
62-
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
57+
MAVEN_CENTRAL_USERNAME: ${{ secrets.OSSRH_USERNAME }}
58+
MAVEN_CENTRAL_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
6359
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
6460
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6561
continue-on-error: ${{ github.event.inputs.dry_run == false }}
@@ -70,7 +66,7 @@ jobs:
7066
echo "Release failed. Rolling back..."
7167
mvn -B release:rollback -Prelease
7268
env:
73-
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
74-
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
69+
MAVEN_CENTRAL_USERNAME: ${{ secrets.OSSRH_USERNAME }}
70+
MAVEN_CENTRAL_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
7571
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
7672
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

pom.xml

Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,18 @@
8383
<maven.jar.plugin.version>3.4.2</maven.jar.plugin.version>
8484
<maven.github.release.plugin.version>1.6.0</maven.github.release.plugin.version>
8585
<project.build.outputTimestamp>2025-03-12T01:44:22Z</project.build.outputTimestamp>
86+
87+
<!-- Default SCM Properties -->
88+
<scm.connection>scm:git:https://github.com/CycloneDX/cyclonedx-core-java.git</scm.connection>
89+
<scm.developerConnection>scm:git:https://github.com/CycloneDX/cyclonedx-core-java.git</scm.developerConnection>
90+
<scm.url>https://github.com/CycloneDX/cyclonedx-core-java.git</scm.url>
8691
</properties>
8792

8893
<scm>
89-
<connection>scm:git:https://github.com/CycloneDX/cyclonedx-core-java.git</connection>
90-
<url>https://github.com/CycloneDX/cyclonedx-core-java.git</url>
91-
<developerConnection>scm:git:https://github.com/CycloneDX/cyclonedx-core-java.git</developerConnection>
94+
<connection>${scm.connection}</connection>
95+
<developerConnection>${scm.developerConnection}</developerConnection>
9296
<tag>HEAD</tag>
97+
<url>${scm.url}</url>
9398
</scm>
9499

95100
<issueManagement>
@@ -102,48 +107,6 @@
102107
<url>https://github.com/CycloneDX/cyclonedx-core-java/actions</url>
103108
</ciManagement>
104109

105-
<distributionManagement>
106-
<snapshotRepository>
107-
<id>ossrh</id>
108-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
109-
</snapshotRepository>
110-
<repository>
111-
<id>ossrh</id>
112-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
113-
</repository>
114-
</distributionManagement>
115-
116-
<repositories>
117-
<repository>
118-
<id>maven-central</id>
119-
<url>https://repo1.maven.org/maven2</url>
120-
</repository>
121-
<!-- Resolve snapshot releases -->
122-
<repository>
123-
<id>ossrh-snapshot</id>
124-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
125-
<snapshots>
126-
<updatePolicy>always</updatePolicy>
127-
<enabled>true</enabled>
128-
</snapshots>
129-
</repository>
130-
</repositories>
131-
132-
<pluginRepositories>
133-
<pluginRepository>
134-
<id>ossrh-snapshot</id>
135-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
136-
<snapshots>
137-
<updatePolicy>always</updatePolicy>
138-
<enabled>true</enabled>
139-
</snapshots>
140-
<releases>
141-
<updatePolicy>always</updatePolicy>
142-
<enabled>true</enabled>
143-
</releases>
144-
</pluginRepository>
145-
</pluginRepositories>
146-
147110
<dependencyManagement>
148111
<dependencies>
149112
<dependency>
@@ -298,19 +261,25 @@
298261
</executions>
299262
</plugin>
300263
<plugin>
301-
<groupId>de.jutzig</groupId>
302-
<artifactId>github-release-plugin</artifactId>
303-
<version>${maven.github.release.plugin.version}</version>
264+
<groupId>org.apache.maven.plugins</groupId>
265+
<artifactId>maven-release-plugin</artifactId>
266+
<version>3.1.1</version>
304267
<configuration>
305-
<tag>${project.artifactId}-${project.version}</tag>
306-
<fileSets>
307-
<fileSet>
308-
<directory>${project.build.directory}</directory>
309-
<includes>
310-
<include>${project.build.finalName}.jar</include>
311-
</includes>
312-
</fileSet>
313-
</fileSets>
268+
<projectVersionPolicyId>SemVerVersionPolicy</projectVersionPolicyId>
269+
<tagNameFormat>@{project.artifactId}-@{project.version}</tagNameFormat>
270+
<useReleaseProfile>false</useReleaseProfile>
271+
<releaseProfiles>release</releaseProfiles>
272+
<goals>deploy</goals>
273+
</configuration>
274+
</plugin>
275+
<plugin>
276+
<groupId>org.sonatype.central</groupId>
277+
<artifactId>central-publishing-maven-plugin</artifactId>
278+
<version>0.8.0</version>
279+
<extensions>true</extensions>
280+
<configuration>
281+
<autoPublish>true</autoPublish>
282+
<publishingServerId>central</publishingServerId>
314283
</configuration>
315284
</plugin>
316285
</plugins>
@@ -336,6 +305,27 @@
336305
</build>
337306

338307
<profiles>
308+
<profile>
309+
<!--
310+
When running in GitHub Actions, the SCM connection must be via HTTPS
311+
so that the GITHUB_TOKEN injected by Actions can be used to authenticate.
312+
313+
Connection URLs target the repository for which the Actions workflow is
314+
running, enabling the release process to be tested in forks.
315+
-->
316+
<id>github-actions</id>
317+
<activation>
318+
<property>
319+
<name>env.GITHUB_ACTIONS</name>
320+
<value>true</value>
321+
</property>
322+
</activation>
323+
<properties>
324+
<scm.connection>scm:git:https://github.com/${env.GITHUB_REPOSITORY}.git</scm.connection>
325+
<scm.developerConnection>scm:git:https://github.com/${env.GITHUB_REPOSITORY}.git</scm.developerConnection>
326+
<scm.url>https://github.com/${env.GITHUB_REPOSITORY}.git</scm.url>
327+
</properties>
328+
</profile>
339329
<profile>
340330
<id>release</id>
341331
<activation>

0 commit comments

Comments
 (0)