Skip to content

Commit b6a36aa

Browse files
committed
chore(maven): configure Maven Central publishing
Update Maven POMs to support publishing to Maven Central: - Use ${revision} property for CI-friendly versioning - Configure parent POM to skip install/deploy/sign - Enable install/deploy/sign for maven-plugin module only - Migrate from nexus-staging-maven-plugin to central-publishing-maven-plugin - Add release profile with GPG signing and Central publishing - Use version constant in maven-analyzer instead of hardcoded value
1 parent 883f65f commit b6a36aa

File tree

5 files changed

+83
-44
lines changed

5 files changed

+83
-44
lines changed

packages/maven/maven-plugin/pom.xml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>dev.nx</groupId>
77
<artifactId>nx-parent</artifactId>
8-
<version>0.0.1</version>
8+
<version>${revision}</version>
99
<relativePath>../../../pom.xml</relativePath>
1010
</parent>
1111

@@ -16,6 +16,12 @@
1616
<name>Nx Maven Plugin</name>
1717
<description>Maven plugin for Nx integration and project analysis</description>
1818

19+
<properties>
20+
<!-- Enable install, deploy, and signing for this module -->
21+
<maven.install.skip>false</maven.install.skip>
22+
<maven.deploy.skip>false</maven.deploy.skip>
23+
<maven.gpg.skip>false</maven.gpg.skip>
24+
</properties>
1925

2026
<dependencies>
2127
<!-- Maven Plugin API -->
@@ -182,4 +188,30 @@
182188
<sourceDirectory>src/main/kotlin</sourceDirectory>
183189
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
184190
</build>
191+
192+
<profiles>
193+
<profile>
194+
<id>release</id>
195+
<build>
196+
<plugins>
197+
<plugin>
198+
<groupId>org.apache.maven.plugins</groupId>
199+
<artifactId>maven-source-plugin</artifactId>
200+
</plugin>
201+
<plugin>
202+
<groupId>org.apache.maven.plugins</groupId>
203+
<artifactId>maven-javadoc-plugin</artifactId>
204+
</plugin>
205+
<plugin>
206+
<groupId>org.apache.maven.plugins</groupId>
207+
<artifactId>maven-gpg-plugin</artifactId>
208+
</plugin>
209+
<plugin>
210+
<groupId>org.sonatype.central</groupId>
211+
<artifactId>central-publishing-maven-plugin</artifactId>
212+
</plugin>
213+
</plugins>
214+
</build>
215+
</profile>
216+
</profiles>
185217
</project>

packages/maven/src/plugins/maven-analyzer.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ describe('Maven Analyzer', () => {
214214
mockChild.emit('close', 1);
215215
});
216216

217-
await expect(promise).rejects.toThrow('Maven analysis failed with code 1');
217+
await expect(promise).rejects.toThrow(
218+
'Maven analysis failed with code 1'
219+
);
218220
});
219221

220222
it('should handle spawn error', async () => {
@@ -262,8 +264,12 @@ describe('Maven Analyzer', () => {
262264
mockChild.stderr = new EventEmitter();
263265
mockChild.pid = 1234;
264266

265-
const stdoutSpy = jest.spyOn(process.stdout, 'write').mockImplementation();
266-
const stderrSpy = jest.spyOn(process.stderr, 'write').mockImplementation();
267+
const stdoutSpy = jest
268+
.spyOn(process.stdout, 'write')
269+
.mockImplementation();
270+
const stderrSpy = jest
271+
.spyOn(process.stderr, 'write')
272+
.mockImplementation();
267273

268274
(spawn as jest.Mock).mockReturnValue(mockChild);
269275
(readJsonFile as jest.Mock).mockReturnValue({

packages/maven/src/plugins/maven-analyzer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { spawn } from 'child_process';
44
import { logger, readJsonFile } from '@nx/devkit';
55
import { workspaceDataDirectory } from 'nx/src/utils/cache-directory';
66
import { MavenAnalysisData, MavenPluginOptions } from './types';
7+
import { mavenPluginVersion } from '../utils/versions';
78

89
/**
910
* Detect Maven executable: mvnd > mvnw > mvn
@@ -67,7 +68,7 @@ export async function runMavenAnalysis(
6768
const mavenExecutable = detectMavenExecutable(workspaceRoot);
6869

6970
const mavenArgs = [
70-
'dev.nx.maven:nx-maven-plugin:0.0.1:analyze',
71+
`dev.nx.maven:nx-maven-plugin:${mavenPluginVersion}:analyze`,
7172
'-am',
7273
`-DoutputFile=${outputFile}`,
7374
`-DworkspaceRoot=${workspaceRoot}`,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export const nxVersion = require('../../package.json').version;
2-
export const mavenPluginVersion = '0.0.1';
2+
export const mavenPluginVersion = '0.0.1-SNAPSHOT';

pom.xml

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>dev.nx</groupId>
77
<artifactId>nx-parent</artifactId>
8-
<version>0.0.1</version>
8+
<version>${revision}</version>
99
<packaging>pom</packaging>
1010

1111
<name>Nx Parent</name>
@@ -35,11 +35,20 @@
3535
<url>https://github.com/nrwl/nx/tree/master</url>
3636
</scm>
3737

38+
3839
<modules>
3940
<module>packages/maven/maven-plugin</module>
4041
</modules>
4142

4243
<properties>
44+
<!-- Version -->
45+
<revision>0.0.1-SNAPSHOT</revision>
46+
47+
<!-- Skip deploying parent POM -->
48+
<maven.deploy.skip>true</maven.deploy.skip>
49+
<maven.install.skip>true</maven.install.skip>
50+
<maven.gpg.skip>true</maven.gpg.skip>
51+
4352
<!-- Build Properties -->
4453
<maven.compiler.source>17</maven.compiler.source>
4554
<maven.compiler.target>17</maven.compiler.target>
@@ -64,7 +73,6 @@
6473
<maven.source.plugin.version>3.3.0</maven.source.plugin.version>
6574
<maven.javadoc.plugin.version>3.6.3</maven.javadoc.plugin.version>
6675
<maven.gpg.plugin.version>3.1.0</maven.gpg.plugin.version>
67-
<nexus.staging.plugin.version>1.6.13</nexus.staging.plugin.version>
6876
</properties>
6977

7078
<dependencyManagement>
@@ -255,45 +263,37 @@
255263
</build>
256264

257265
<profiles>
258-
<!-- Release Profile -->
266+
<!-- Release Profile - plugins configured here are inherited by child modules -->
259267
<profile>
260268
<id>release</id>
261269
<build>
262-
<plugins>
263-
<plugin>
264-
<groupId>org.apache.maven.plugins</groupId>
265-
<artifactId>maven-source-plugin</artifactId>
266-
</plugin>
267-
<plugin>
268-
<groupId>org.apache.maven.plugins</groupId>
269-
<artifactId>maven-javadoc-plugin</artifactId>
270-
</plugin>
271-
<plugin>
272-
<groupId>org.apache.maven.plugins</groupId>
273-
<artifactId>maven-gpg-plugin</artifactId>
274-
<version>${maven.gpg.plugin.version}</version>
275-
<executions>
276-
<execution>
277-
<id>sign-artifacts</id>
278-
<phase>verify</phase>
279-
<goals>
280-
<goal>sign</goal>
281-
</goals>
282-
</execution>
283-
</executions>
284-
</plugin>
285-
<plugin>
286-
<groupId>org.sonatype.plugins</groupId>
287-
<artifactId>nexus-staging-maven-plugin</artifactId>
288-
<version>${nexus.staging.plugin.version}</version>
289-
<extensions>true</extensions>
290-
<configuration>
291-
<serverId>ossrh</serverId>
292-
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
293-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
294-
</configuration>
295-
</plugin>
296-
</plugins>
270+
<pluginManagement>
271+
<plugins>
272+
<plugin>
273+
<groupId>org.apache.maven.plugins</groupId>
274+
<artifactId>maven-gpg-plugin</artifactId>
275+
<version>${maven.gpg.plugin.version}</version>
276+
<executions>
277+
<execution>
278+
<id>sign-artifacts</id>
279+
<phase>verify</phase>
280+
<goals>
281+
<goal>sign</goal>
282+
</goals>
283+
</execution>
284+
</executions>
285+
</plugin>
286+
<plugin>
287+
<groupId>org.sonatype.central</groupId>
288+
<artifactId>central-publishing-maven-plugin</artifactId>
289+
<version>0.9.0</version>
290+
<extensions>true</extensions>
291+
<configuration>
292+
<publishingServerId>central</publishingServerId>
293+
</configuration>
294+
</plugin>
295+
</plugins>
296+
</pluginManagement>
297297
</build>
298298
</profile>
299299
</profiles>

0 commit comments

Comments
 (0)