Skip to content

Move off the MavenProject and artifact APIs deprecated since Maven 3 - #1548

Open
shuseng8 wants to merge 1 commit into
apache:masterfrom
shuseng8:maven3-deprecations-1547
Open

shuseng8 wants to merge 1 commit into
apache:masterfrom
shuseng8:maven3-deprecations-1547

Conversation

@shuseng8

Copy link
Copy Markdown

Closes #1547.

This replaces the Maven API that has been deprecated since Maven 3 and is listed in the issue. Behaviour and parameters stay the same.

Main code

  • New package-private helper phase/ProjectArtifacts:
    • getDirectDependencyArtifacts: getArtifacts() narrowed to the direct dependencies, meaning artifacts whose dependency trail is the project followed by the artifact. This is the same approach as Replace deprecated MavenProject.getDependencyArtifacts() with getArtifacts() narrowed to direct dependencies maven-war-plugin#695.
    • getReportPluginArtifacts/getReportPluginArtifactMap: read from the model's <reporting> plugins, not from getReportPlugins(), which is itself deprecated in 3.9.16. Each artifact is built the way Maven 3 builds it: maven-plugin at the declared version, or RELEASE when there is no version, with runtime scope.
    • getExtensionArtifacts/getExtensionArtifactMap: read from getBuildExtensions(), as a jar at the declared version or RELEASE.
  • CheckDependencySnapshotsPhase and GenerateReleasePomsPhase now call the helper. The extension map is computed once, before the loop, instead of once per extension.

Test code (AbstractReleaseTestCase)

  • The direct dependency artifacts are now created with DefaultArtifact plus ArtifactHandlerManager, and set with setArtifacts(). ArtifactFactory and get/setDependencyArtifacts() are gone.
  • ArtifactRepository, MavenArtifactRepository, ArtifactRepositoryLayout and ArtifactRepositoryPolicy are gone. The local repository is now a plain File used by the resolver session.
  • Without request-level plugin repositories, the projects' build extensions (which Maven resolves from the plugin repositories) are found through a ChainedLocalRepositoryManager. It reads from a copy of src/test/remote-repository in target/ after the local repository. It uses a copy because the resolver writes base-version files next to the timestamped snapshots it finds.
  • I tried two alternatives first and both broke tests:
    • Adding a plugin repository to the test profile changed the generated release POMs, which broke 23 GenerateReleasePomsPhaseTest comparisons.
    • A mirror for central keeps central's disabled snapshot policy, so the snapshot extension could not be resolved.
  • New ProjectArtifactsTest covers the direct-dependency filter and the report plugin and extension artifacts, with and without versions.

How I tested it (JDK 21, Maven 3.9)

  • mvn -B clean verify -Prun-its passes:
    • maven-release-manager: 778 tests, 0 failures, 18 skipped.
    • maven-release-plugin: 78 unit tests pass.
    • Integration tests: 52 passed, 0 failed, 4 skipped.
  • Compiling with -Dmaven.compiler.showDeprecation=true no longer reports any of the APIs listed in the issue. The only deprecation left in AbstractReleaseTestCase is the existing SimpleLocalRepositoryManagerFactory constructor from Resolver, which the issue does not cover.
  • spotless:apply was run.

CheckDependencySnapshotsPhase and GenerateReleasePomsPhase read the
direct dependency, report plugin and build extension artifacts through
a new ProjectArtifacts helper instead of getDependencyArtifacts(),
getReportArtifacts(), getReportArtifactMap(), getExtensionArtifacts()
and getExtensionArtifactMap(). The direct dependencies are getArtifacts()
narrowed by dependency trail; report plugins and extensions are read
from the model and built the way Maven 3 builds them.

AbstractReleaseTestCase no longer uses ArtifactFactory, ArtifactRepository,
ArtifactRepositoryLayout, ArtifactRepositoryPolicy or get/
setDependencyArtifacts(). Build extensions, which are resolved from the
plugin repositories, are read from a copy of the test repository chained
after the local repository.

Closes apache#1547

Signed-off-by: Shubham <[email protected]>
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