Skip to content

Move off the Maven API deprecated since Maven 3 - #358

Open
Irasha-Senarathna wants to merge 2 commits into
apache:masterfrom
Irasha-Senarathna:remove-deprecated-maven3-api
Open

Irasha-Senarathna wants to merge 2 commits into
apache:masterfrom
Irasha-Senarathna:remove-deprecated-maven3-api

Conversation

@Irasha-Senarathna

Copy link
Copy Markdown

Fixes #357

getDirectDependencies() called the deprecated MavenProject.getDependencyArtifacts() in AggregateProcessRemoteResourcesMojo (listed in the issue) and in ProcessRemoteResourcesMojo (not listed, same problem). It is only used when excludeTransitive=true.

Both mojos now take project.getArtifacts() and keep the artifacts whose dependency trail has two entries. Maven core starts the trail with the project and ends it with the artifact, so two entries means a direct dependency. Both mojos declare requiresDependencyResolution = TEST, so the artifacts and their trails are always set.

The aggregate mojo filters each reactor project before it merges them. An artifact can be direct in one module and transitive in another. The two artifacts are equal, so only one survives the merge, and it can be the transitive one.

Test changes:

  • Nothing tested excludeTransitive. I added one test for process and one for aggregate, and wrote them before the change. They pass on the old and the new code and fail with excludeTransitive=false. The aggregate test also fails if the mojo merges before it filters.
  • stub/ArtifactStub implemented Artifact, which forced the deprecated ArtifactMetadata and ArtifactRepository types into the tests. It is replaced with DefaultArtifact and deleted.
  • testProjectsDoesNotMutateProjectArtifactVersions now uses a timestamped snapshot (1.0-20260926.120000-1). With plain 1.0-SNAPSHOT, the base version is the same as the version, so the test would not catch the getProjects() mutates the project's resolved Artifact versions (side effect) #268 regression. I checked that it still fails with that bug reintroduced.
  • MavenProjectBasicStub no longer calls the deprecated setDependencyArtifacts, setReportArtifacts or setExtensionArtifacts.

No parameters or behavior change.

Still deprecated, in tests only: Maven 3.9 has no non-deprecated MavenSession constructor. The new aggregate test uses the same constructor as the existing testGetProjectsBuildsOnlyExternalArtifacts. I can switch both tests to a Mockito mock if you prefer, but that needs a declared mockito-core test dependency.

mvn -Prun-its verify on JDK 21 with Maven 3.10.2 passes: 59 unit tests, 12 failsafe ITs and 7 invoker ITs. CI covers Maven 4.


To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
check one of the following:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move off the Maven API deprecated since Maven 3

1 participant