Skip to content

Commit 4eb0669

Browse files
committed
Upgrade to Maven 4.0.0-beta-3
1 parent 57fb7fd commit 4eb0669

20 files changed

+114
-903
lines changed

.github/workflows/maven-verify.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ on:
2424
jobs:
2525
build:
2626
name: Verify
27-
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v3
27+
uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v4
28+
with:
29+
ff-maven: "4.0.0-beta-3" # Maven version for fail-fast-build
30+
maven-matrix: '[ "4.0.0-beta-3" ]'

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ under the License.
2323
<parent>
2424
<groupId>org.apache.maven.plugins</groupId>
2525
<artifactId>maven-plugins</artifactId>
26-
<version>41</version>
26+
<version>42</version>
2727
<relativePath />
2828
</parent>
2929

@@ -77,8 +77,8 @@ under the License.
7777
</distributionManagement>
7878

7979
<properties>
80-
<javaVersion>8</javaVersion>
81-
<mavenVersion>4.0.0-alpha-12</mavenVersion>
80+
<javaVersion>17</javaVersion>
81+
<mavenVersion>4.0.0-beta-3</mavenVersion>
8282
<project.build.outputTimestamp>2023-05-17T21:31:27Z</project.build.outputTimestamp>
8383
</properties>
8484

@@ -141,7 +141,7 @@ under the License.
141141
<plugin>
142142
<groupId>org.apache.maven.plugins</groupId>
143143
<artifactId>maven-plugin-plugin</artifactId>
144-
<version>3.10.3-SNAPSHOT</version>
144+
<version>4.0.0-SNAPSHOT</version>
145145
</plugin>
146146
<plugin>
147147
<groupId>org.apache.rat</groupId>

src/main/java/org/apache/maven/plugins/source/AbstractSourceJarMojo.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
import java.util.List;
2929
import java.util.Objects;
3030

31-
import jakarta.inject.Inject;
3231
import org.apache.maven.api.Artifact;
3332
import org.apache.maven.api.Project;
3433
import org.apache.maven.api.Session;
34+
import org.apache.maven.api.Type;
35+
import org.apache.maven.api.di.Inject;
3536
import org.apache.maven.api.model.Resource;
3637
import org.apache.maven.api.plugin.Log;
3738
import org.apache.maven.api.plugin.Mojo;
@@ -152,12 +153,6 @@ public abstract class AbstractSourceJarMojo implements Mojo {
152153
@Parameter(property = "maven.source.includePom", defaultValue = "false")
153154
protected boolean includePom;
154155

155-
/**
156-
* Used for attaching the source jar to the project.
157-
*/
158-
@Inject
159-
protected ProjectManager projectManager;
160-
161156
/**
162157
* The directory where the generated archive file will be put.
163158
*/
@@ -174,7 +169,7 @@ public abstract class AbstractSourceJarMojo implements Mojo {
174169
/**
175170
* Contains the full list of projects in the reactor.
176171
*/
177-
@Parameter(defaultValue = "${reactorProjects}", readonly = true)
172+
@Parameter(defaultValue = "${session.projects}", readonly = true)
178173
protected List<Project> reactorProjects;
179174

180175
/**
@@ -214,6 +209,11 @@ public abstract class AbstractSourceJarMojo implements Mojo {
214209
@Inject
215210
protected Log log;
216211

212+
/**
213+
* Used for attaching the source jar to the project.
214+
*/
215+
protected ProjectManager projectManager;
216+
217217
// ----------------------------------------------------------------------
218218
// Public methods
219219
// ----------------------------------------------------------------------
@@ -231,6 +231,11 @@ public void execute() throws MojoException {
231231
return;
232232
}
233233

234+
projectManager = session.getService(ProjectManager.class);
235+
doExecute();
236+
}
237+
238+
protected void doExecute() {
234239
packageSources(project);
235240
}
236241

@@ -248,7 +253,7 @@ public void execute() throws MojoException {
248253
* @return the compile or test sources
249254
* @throws MojoException in case of an error.
250255
*/
251-
protected abstract List<String> getSources(Project p) throws MojoException;
256+
protected abstract List<Path> getSources(Project p) throws MojoException;
252257

253258
/**
254259
* @param p {@link Project} not null
@@ -262,7 +267,8 @@ public void execute() throws MojoException {
262267
* @throws MojoException in case of an error.
263268
*/
264269
protected void packageSources(Project p) throws MojoException {
265-
if (!"pom".equals(p.getPackaging()) && !"bom".equals(p.getPackaging())) {
270+
String type = p.getPackaging().type().id();
271+
if (!Type.POM.equals(type) && !Type.BOM.equals(type)) {
266272
packageSources(Collections.singletonList(p));
267273
}
268274
}
@@ -272,10 +278,11 @@ protected void packageSources(Project p) throws MojoException {
272278
* @throws MojoException in case of an error.
273279
*/
274280
protected void packageSources(List<Project> theProjects) throws MojoException {
275-
if (!project.getArtifact().getClassifier().isEmpty()) {
281+
Artifact currentProjectArtifact = project.getMainArtifact().get();
282+
if (!currentProjectArtifact.getClassifier().isEmpty()) {
276283
getLog().warn("NOT adding sources to artifacts with classifier as Maven only supports one classifier "
277-
+ "per artifact. Current artifact [" + project.getArtifact().key() + "] has a ["
278-
+ project.getArtifact().getClassifier() + "] classifier.");
284+
+ "per artifact. Current artifact [" + currentProjectArtifact.key() + "] has a ["
285+
+ currentProjectArtifact.getClassifier() + "] classifier.");
279286

280287
return;
281288
}
@@ -285,7 +292,8 @@ protected void packageSources(List<Project> theProjects) throws MojoException {
285292
for (Project pItem : theProjects) {
286293
Project subProject = getProject(pItem);
287294

288-
if ("pom".equals(subProject.getPackaging()) || "bom".equals(subProject.getPackaging())) {
295+
String type = subProject.getPackaging().type().id();
296+
if (Type.POM.equals(type) || Type.BOM.equals(type)) {
289297
continue;
290298
}
291299

@@ -344,17 +352,14 @@ protected void packageSources(List<Project> theProjects) throws MojoException {
344352
protected void archiveProjectContent(Project project, Archiver archiver) throws MojoException {
345353
if (includePom) {
346354
try {
347-
File pom = project.getPomPath().get().toFile();
355+
File pom = project.getPomPath().toFile();
348356
archiver.addFile(pom, pom.getName());
349357
} catch (ArchiverException e) {
350358
throw new MojoException("Error adding POM file to target jar file.", e);
351359
}
352360
}
353361

354-
for (String s : getSources(project)) {
355-
356-
Path sourceDirectory = Paths.get(s);
357-
362+
for (Path sourceDirectory : getSources(project)) {
358363
if (Files.exists(sourceDirectory)) {
359364
addDirectory(archiver, sourceDirectory, getCombinedIncludes(null), getCombinedExcludes(null));
360365
}

src/main/java/org/apache/maven/plugins/source/AggregatorSourceJarMojo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@
1818
*/
1919
package org.apache.maven.plugins.source;
2020

21+
import org.apache.maven.api.Type;
2122
import org.apache.maven.api.plugin.MojoException;
2223
import org.apache.maven.api.plugin.annotations.Execute;
23-
import org.apache.maven.api.plugin.annotations.LifecyclePhase;
2424
import org.apache.maven.api.plugin.annotations.Mojo;
2525

2626
/**
2727
* Aggregate sources for all modules in an aggregator project.
2828
*
2929
* @since 2.0.3
3030
*/
31-
@Mojo(name = "aggregate", defaultPhase = LifecyclePhase.PACKAGE, aggregator = true)
32-
@Execute(phase = LifecyclePhase.GENERATE_SOURCES)
31+
@Mojo(name = "aggregate", defaultPhase = "package", aggregator = true)
32+
@Execute(phase = "generate-sources")
3333
public class AggregatorSourceJarMojo extends SourceJarMojo {
3434
/**
3535
* {@inheritDoc}
3636
*/
3737
@Override
38-
public void execute() throws MojoException {
39-
if ("pom".equals(getProject().getPackaging())) {
38+
protected void doExecute() throws MojoException {
39+
if (Type.POM.equals(getProject().getPackaging().type().id())) {
4040
packageSources(reactorProjects);
4141
}
4242
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.plugins.source;
20+
21+
import org.apache.maven.api.di.Named;
22+
import org.apache.maven.api.di.Provides;
23+
import org.apache.maven.api.di.Singleton;
24+
import org.codehaus.plexus.archiver.jar.JarArchiver;
25+
26+
@Named
27+
public class Archivers {
28+
29+
@Provides
30+
@Singleton
31+
@Named("jar")
32+
static JarArchiver createJarArchiver() {
33+
return new JarArchiver();
34+
}
35+
}

src/main/java/org/apache/maven/plugins/source/SourceJarMojo.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.plugins.source;
2020

2121
import org.apache.maven.api.plugin.annotations.Execute;
22-
import org.apache.maven.api.plugin.annotations.LifecyclePhase;
2322
import org.apache.maven.api.plugin.annotations.Mojo;
2423

2524
/**
@@ -28,8 +27,8 @@
2827
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
2928
* @since 2.0.3
3029
*/
31-
@Mojo(name = "jar", defaultPhase = LifecyclePhase.PACKAGE)
32-
@Execute(phase = LifecyclePhase.GENERATE_SOURCES)
30+
@Mojo(name = "jar", defaultPhase = "package")
31+
@Execute(phase = "generate-sources")
3332
public class SourceJarMojo extends SourceJarNoForkMojo {
3433
// no op
3534
}

src/main/java/org/apache/maven/plugins/source/SourceJarNoForkMojo.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
*/
1919
package org.apache.maven.plugins.source;
2020

21+
import java.nio.file.Path;
2122
import java.util.Collections;
2223
import java.util.List;
2324

2425
import org.apache.maven.api.Project;
26+
import org.apache.maven.api.ProjectScope;
2527
import org.apache.maven.api.model.Resource;
26-
import org.apache.maven.api.plugin.annotations.LifecyclePhase;
2728
import org.apache.maven.api.plugin.annotations.Mojo;
2829
import org.apache.maven.api.plugin.annotations.Parameter;
2930

@@ -34,7 +35,7 @@
3435
* @author pgier
3536
* @since 2.1
3637
*/
37-
@Mojo(name = "jar-no-fork", defaultPhase = LifecyclePhase.PACKAGE)
38+
@Mojo(name = "jar-no-fork", defaultPhase = "package")
3839
public class SourceJarNoForkMojo extends AbstractSourceJarMojo {
3940
/**
4041
* @since 2.2
@@ -45,8 +46,8 @@ public class SourceJarNoForkMojo extends AbstractSourceJarMojo {
4546
/**
4647
* {@inheritDoc}
4748
*/
48-
protected List<String> getSources(Project p) {
49-
return projectManager.getCompileSourceRoots(p);
49+
protected List<Path> getSources(Project p) {
50+
return projectManager.getCompileSourceRoots(p, ProjectScope.MAIN);
5051
}
5152

5253
/**
@@ -57,7 +58,7 @@ protected List<Resource> getResources(Project p) {
5758
return Collections.emptyList();
5859
}
5960

60-
return projectManager.getResources(p);
61+
return projectManager.getResources(p, ProjectScope.MAIN);
6162
}
6263

6364
/**

src/main/java/org/apache/maven/plugins/source/TestSourceGeneratedJarMojo.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@
1919
package org.apache.maven.plugins.source;
2020

2121
import org.apache.maven.api.plugin.annotations.Execute;
22-
import org.apache.maven.api.plugin.annotations.LifecyclePhase;
2322
import org.apache.maven.api.plugin.annotations.Mojo;
2423

2524
/**
2625
* This plugin bundles all the test sources into a jar archive.
2726
*
2827
* @since 2.2
2928
*/
30-
@Mojo(name = "generated-test-jar", defaultPhase = LifecyclePhase.PACKAGE)
31-
@Execute(phase = LifecyclePhase.GENERATE_TEST_SOURCES)
29+
@Mojo(name = "generated-test-jar", defaultPhase = "package")
30+
@Execute(phase = "generate-test-sources")
3231
public class TestSourceGeneratedJarMojo extends TestSourceJarNoForkMojo {
3332
// no op
3433
}

src/main/java/org/apache/maven/plugins/source/TestSourceJarMojo.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@
1919
package org.apache.maven.plugins.source;
2020

2121
import org.apache.maven.api.plugin.annotations.Execute;
22-
import org.apache.maven.api.plugin.annotations.LifecyclePhase;
2322
import org.apache.maven.api.plugin.annotations.Mojo;
2423

2524
/**
2625
* This plugin bundles all the test sources into a jar archive.
2726
*
2827
* @since 2.0.3
2928
*/
30-
@Mojo(name = "test-jar", defaultPhase = LifecyclePhase.PACKAGE)
31-
@Execute(phase = LifecyclePhase.GENERATE_SOURCES)
29+
@Mojo(name = "test-jar", defaultPhase = "package")
30+
@Execute(phase = "generate-sources")
3231
public class TestSourceJarMojo extends TestSourceJarNoForkMojo {
3332
// no op
3433
}

src/main/java/org/apache/maven/plugins/source/TestSourceJarNoForkMojo.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
*/
1919
package org.apache.maven.plugins.source;
2020

21+
import java.nio.file.Path;
2122
import java.util.Collections;
2223
import java.util.List;
2324

2425
import org.apache.maven.api.Project;
26+
import org.apache.maven.api.ProjectScope;
2527
import org.apache.maven.api.model.Resource;
26-
import org.apache.maven.api.plugin.annotations.LifecyclePhase;
2728
import org.apache.maven.api.plugin.annotations.Mojo;
2829
import org.apache.maven.api.plugin.annotations.Parameter;
2930

@@ -34,7 +35,7 @@
3435
*
3536
* @since 2.1
3637
*/
37-
@Mojo(name = "test-jar-no-fork", defaultPhase = LifecyclePhase.PACKAGE)
38+
@Mojo(name = "test-jar-no-fork", defaultPhase = "package")
3839
public class TestSourceJarNoForkMojo extends AbstractSourceJarMojo {
3940
/**
4041
* @since 2.2
@@ -45,8 +46,8 @@ public class TestSourceJarNoForkMojo extends AbstractSourceJarMojo {
4546
/**
4647
* {@inheritDoc}
4748
*/
48-
protected List<String> getSources(Project p) {
49-
return projectManager.getTestCompileSourceRoots(p);
49+
protected List<Path> getSources(Project p) {
50+
return projectManager.getCompileSourceRoots(p, ProjectScope.TEST);
5051
}
5152

5253
/**
@@ -57,7 +58,7 @@ protected List<Resource> getResources(Project p) {
5758
return Collections.emptyList();
5859
}
5960

60-
return projectManager.getTestResources(p);
61+
return projectManager.getResources(p, ProjectScope.TEST);
6162
}
6263

6364
/**

0 commit comments

Comments
 (0)