Skip to content

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Oct 8, 2025

Summary

This PR implements automatic phase name upgrades when upgrading Maven projects from model version 4.0.0 to 4.1.0. The deprecated Maven 3 phase names are automatically converted to their Maven 4 equivalents.

Changes Made

Phase Mappings

The following deprecated phase names are automatically upgraded:

  • pre-cleanbefore:clean
  • post-cleanafter:clean
  • pre-integration-testbefore:integration-test
  • post-integration-testafter:integration-test
  • pre-sitebefore:site
  • post-siteafter:site

Implementation Details

  • Enhanced ModelUpgradeStrategy.java: Added upgradePhases() method that processes all plugin executions
  • Uses Maven API Constants: Leverages Lifecycle.BEFORE, Lifecycle.AFTER, Lifecycle.Phase.CLEAN, Lifecycle.Phase.INTEGRATION_TEST, and Lifecycle.SITE for consistency
  • Comprehensive Coverage: Processes phases in build/plugins, build/pluginManagement, and profile/build/plugins sections
  • Version-Specific: Only applies when upgrading to model version 4.1.0 or higher

Testing

  • Added comprehensive unit tests covering all phase upgrade scenarios
  • Tests verify upgrades work in all POM contexts (main build, pluginManagement, profiles)
  • Tests ensure non-deprecated phases are preserved unchanged
  • Tests confirm phase upgrades only occur when upgrading to 4.1.0+

Usage

Users can now run:

mvn mvnup:apply --model-version=4.1.0

And their POM files will be automatically upgraded with:

  1. Updated model version and namespace
  2. Converted modules to subprojects elements
  3. NEW: Automatic conversion of deprecated phase names to Maven 4 equivalents

Example Transformation

Before (Maven 4.0.0):

<execution>
    <phase>pre-clean</phase>
    <goals><goal>clean</goal></goals>
</execution>

After (Maven 4.1.0):

<execution>
    <phase>before:clean</phase>
    <goals><goal>clean</goal></goals>
</execution>

Backward Compatibility

  • Non-deprecated phase names are preserved unchanged
  • Phase upgrades only apply when explicitly upgrading to model version 4.1.0+
  • No impact on existing Maven 4.0.0 projects unless explicitly upgraded

Testing

  • All existing tests continue to pass
  • New comprehensive test suite covers all phase upgrade scenarios
  • Full Maven build succeeds

This enhancement provides a smooth migration path for Maven projects upgrading to version 4.1.0 by automatically handling the deprecated phase name conversions.


Pull Request opened by Augment Code with guidance from the PR author

gnodet added 2 commits October 8, 2025 06:36
This commit implements automatic phase name upgrades when upgrading
Maven projects from model version 4.0.0 to 4.1.0. The deprecated
Maven 3 phase names are automatically converted to their Maven 4
equivalents:

- pre-clean → before:clean
- post-clean → after:clean
- pre-integration-test → before:integration-test
- post-integration-test → after:integration-test
- pre-site → before:site
- post-site → after:site

The upgrade functionality:
- Only applies when upgrading to model version 4.1.0 or higher
- Processes all plugin executions in build/plugins, build/pluginManagement,
  and profile/build/plugins sections
- Preserves non-deprecated phase names unchanged
- Includes comprehensive test coverage for all scenarios

This enhancement ensures that Maven projects upgrading to 4.1.0 will
automatically have their deprecated phase references updated to use
the new Maven 4 phase naming convention.
Replace hardcoded phase name strings with proper Maven API constants:
- Use Lifecycle.BEFORE and Lifecycle.AFTER for phase prefixes
- Use Lifecycle.Phase.CLEAN and Lifecycle.Phase.INTEGRATION_TEST for phase names
- Use Lifecycle.SITE for site lifecycle phase

This ensures consistency with Maven's lifecycle definitions and makes
the code more maintainable by using the official API constants.
@gnodet gnodet added bug Something isn't working backport-to-4.0.x labels Oct 8, 2025
@gnodet gnodet merged commit 1376aa9 into apache:master Oct 8, 2025
54 of 57 checks passed
@github-actions github-actions bot added this to the 4.1.0 milestone Oct 8, 2025
@gnodet
Copy link
Contributor Author

gnodet commented Oct 8, 2025

💚 All backports created successfully

Status Branch Result
maven-4.0.x

Questions ?

Please refer to the Backport tool documentation

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

Labels

backport-to-4.0.x bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants