Maven - wrapper
Table of Contents
Missing wrapper files in Docker context
Sometimes, when running pipelines in Jenkins or GitHub actions, it may complain about mising files or directories.
e.g. The directory .mnv is missing
Especially, when building docker images
Common causes with wrapper in CI/CD pipelines
Avoid custom configuration as much as possible and go with the standard flow.
If you need to regerate the wrapper, do it.
See https://www.baeldung.com/maven-wrapper
Using vs not using mvn wrapper
The decision to use or not use the Maven Wrapper (mvnw) depends on project requirements and development environment consistency.
Using the Maven Wrapper (mvnw)
- Ensured Version Consistency: The Maven Wrapper guarantees that all developers and build environments use the exact same Maven version, preventing “it works on my machine” issues.
- Simplified Setup for New Developers: New team members or contributors can easily build the project without needing to install Maven globally, as the wrapper handles downloading the correct version. Only a JDK is required.
- Reproducible Builds: By ensuring a specific Maven version, the wrapper contributes to more consistent and reproducible builds across different machines and environments.
- Encapsulation from User Environment: The project becomes less dependent on the user’s local Maven installation, as the wrapper manages the required Maven version.
Not Using the Maven Wrapper (relying on a global Maven installation)
- Less Project Overhead: Not including the wrapper files (mvnw, mvnw.cmd, .mvn/wrapper/maven-wrapper.properties, and maven-wrapper.jar) reduces the number of files in the project repository.
- Centralized Maven Management: If all projects in an organization use a consistent, globally installed Maven version, managing a single installation might be preferred.
- Direct Control over Maven Installation: Developers have full control over their local Maven installation and can easily switch between versions if needed for different projects.
Key Considerations
- Team Collaboration: For projects with multiple contributors or in CI/CD pipelines, the Maven Wrapper is highly recommended for ensuring consistent builds.
- Project Lifespan: For long-lived projects, the wrapper can simplify future Maven version upgrades by managing the update within the project.
- Developer Preference: Some developers may prefer to manage their own global Maven installations and avoid the wrapper files in their projects.
In essence, the Maven Wrapper prioritizes consistency and ease of setup, while relying on a global Maven installation offers more direct control and reduced project file overhead. The optimal choice depends on the specific project context and team practices.