Skip to content

Fix Maven wrapper support for snapshot distributions #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2025

Conversation

gnodet
Copy link
Contributor

@gnodet gnodet commented Jul 13, 2025

Problem

The Maven wrapper scripts (only-mvnw and only-mvnw.cmd) previously failed when using snapshot distributions because they assumed the directory name inside the ZIP file would match the filename pattern. However, for snapshots:

  • Filename: apache-maven-4.1.0-20250710.120440-1-bin.zip
  • Directory inside ZIP: apache-maven-4.1.0-SNAPSHOT/

This mismatch caused the script to fail when trying to access the extracted directory, as reported in apache/maven#10894 (comment).

Solution

This PR implements dynamic directory detection instead of assuming directory names match filename patterns:

Changes Made

  1. Fixed Unix Shell Script (only-mvnw):

    • Added logic to dynamically detect the actual extracted directory by looking for the Maven executable
    • Provides clear error messages when no valid Maven distribution is found
    • Maintains backward compatibility with regular releases
  2. Fixed Windows PowerShell Script (only-mvnw.cmd):

    • Applied the same fix for Windows compatibility
    • Uses PowerShell-appropriate directory detection logic
  3. Added Comprehensive Tests:

    • Created SnapshotDistributionTest.java with unit tests for snapshot URL handling
    • Added integration test project for snapshot distribution scenarios
    • Verified backward compatibility with regular releases
  4. Updated Documentation:

    • Updated index.md to mention snapshot support with example URLs
    • Clarified that the wrapper now works with "any version including snapshots"

Key Benefits

  • Dynamic Directory Detection: No longer assumes directory names match filenames
  • Backward Compatibility: Regular Maven releases continue to work exactly as before
  • Cross-Platform: Fixed both Unix and Windows scripts
  • Robust Error Handling: Clear error messages for debugging
  • Comprehensive Testing: Unit and integration tests ensure reliability

Testing

  • All existing tests pass
  • New snapshot distribution tests pass
  • Manual verification confirms the fix works for both snapshot and regular distributions

Example Usage

After this fix, users can use snapshot distributions like:

distributionUrl=https://repository.apache.org/content/repositories/snapshots/org/apache/maven/apache-maven/4.1.0-SNAPSHOT/apache-maven-4.1.0-20250710.120440-1-bin.zip

Fixes #10894 (comment)


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

The Maven wrapper scripts (only-mvnw and only-mvnw.cmd) previously failed
when using snapshot distributions because they assumed the directory name
inside the ZIP file would match the filename pattern. However, for snapshots:
- Filename: apache-maven-4.1.0-20250710.120440-1-bin.zip
- Directory: apache-maven-4.1.0-SNAPSHOT/

This mismatch caused the script to fail when trying to access the extracted
directory.

Changes:
- Modified only-mvnw to dynamically detect the actual extracted directory
  by looking for the Maven executable instead of assuming the name
- Applied the same fix to only-mvnw.cmd for Windows compatibility
- Added comprehensive tests in SnapshotDistributionTest.java
- Added integration test for snapshot distribution handling
- Updated documentation to mention snapshot support

The fix maintains backward compatibility with regular releases while
enabling support for Maven snapshot distributions.

Fixes: apache/maven#10894 (comment)
@gnodet gnodet force-pushed the fix-snapshot-distribution-support branch from 7e63da1 to 82c9403 Compare July 16, 2025 20:44
@gnodet gnodet added the enhancement New feature or request label Jul 21, 2025
@gnodet gnodet merged commit c0085af into apache:master Jul 22, 2025
21 checks passed
@gnodet gnodet deleted the fix-snapshot-distribution-support branch July 22, 2025 05:44
@github-actions github-actions bot added this to the 3.3.3 milestone Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants