Install Mavenπ± Beginner
Because Maven is written in Java, it requires a JDK (Java Development Kit) to run. You can either install it globally on your machine, or (highly recommended) use a Maven Wrapper bundled with your project.
What is the Maven Wrapper?
The Maven Wrapper (mvnw) is a script included in the root of most modern Java projects (like those generated by Spring Boot). When you run it, it automatically downloads and uses the exact version of Maven specified for that project, entirely bypassing your system's global Maven installation.
Why Use the Wrapper?
Imagine a team of 10 developers. If they all have different versions of Maven installed globally, the build might pass for some and fail for others. The wrapper guarantees that every developerβand your CI/CD pipelineβbuilds the project using the exact same Maven version, ensuring 100% reproducible builds.
How to Run Maven Commands
To use the wrapper, open your terminal at the root of your project and run:
# macOS / Linux (notice the ./)
./mvnw -version
# Windows
mvnw.cmd -versionHow to Install Maven Globally (Alternative)
If you are building a project from scratch without a wrapper, you can install Maven globally:
# macOS (using Homebrew)
brew install maven
# Verify global installation
mvn -versionmvn -version reports the wrong Java version, Maven is picking up the wrong path. Ensure your JAVA_HOME environment variable is correctly set and pointing to your intended JDK (e.g., JDK 21).