What is the Maven wrapper (mvnw) and why should you use it?
BeginnerConceptJava builds (Maven, Gradle, JAR, WAR)
Answer
Short answer
The Maven wrapper is a small script (mvnw / mvnw.cmd) plus a .mvn/wrapper/ folder committed to the repo. When you run ./mvnw, it downloads and uses the exact Maven version the project specifies, so every developer and every CI agent builds with the same Maven.
Example
./mvnw -v # shows the project's Maven version
./mvnw clean package # same as mvn clean package, with the pinned version
cat .mvn/wrapper/maven-wrapper.properties
# distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/...
Why it matters
- No need to install Maven on build agents — only Java.
- No "works on my machine" bugs from different Maven versions.
- Gradle has the same idea:
./gradlew.
Tip
If CI can't reach the internet, point distributionUrl at your Nexus so the wrapper downloads Maven from there.
What to say in the interview
"The wrapper pins the Maven version in the repo and downloads it on first use, so builds are reproducible across laptops and CI without installing Maven on agents."
All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Java apps: Maven, Gradle, JAR & WAR
More on Java builds (Maven, Gradle, JAR, WAR)
What is pom.xml and what is it used for?BeginnerHow do you build and run a Java project with Maven?BeginnerWhat is the difference between a JAR and a WAR file?BeginnerWhat is Gradle and how is it different from Maven?BeginnerHow do you configure a Spring Boot application for different environments?BeginnerA Maven build fails in the pipeline with "Could not resolve dependencies". How do you fix it?Intermediate