How to Fix Maven Wrapper Not Found Error
In this tutorial, you'll learn about How to Fix Maven Wrapper Not Found Error. We cover key concepts, practical examples, and best practices.
The Problem
You get mvnw: command not found or The Maven Wrapper is not present in the project when running ./mvnw clean install. The mvnw script and its .mvn/wrapper/ directory are missing, often after cloning a repository that excluded generated files via .gitignore, or when starting a project without initializing the wrapper.
Quick Fix
1. Generate the Maven wrapper using an installed Maven
If Maven is available on your system, generate the wrapper files:
mvn wrapper:wrapper -Dmaven=3.9.6
Expected output:
[INFO] --- wrapper:3.2.0:wrapper (default-cli) @ your-project ---
[INFO] Generating Maven Wrapper for version 3.9.6
[INFO] BUILD SUCCESS
This creates mvnw, mvnw.cmd, and the .mvn/wrapper/ directory.
2. Download wrapper files manually if Maven is not installed
mkdir -p .mvn/wrapper
curl -sL https://github.com/takari/maven-wrapper/raw/main/mvnw -o mvnw
curl -sL https://github.com/takari/maven-wrapper/raw/main/mvnw.cmd -o mvnw.cmd
curl -sL https://github.com/takari/maven-wrapper/raw/main/.mvn/wrapper/maven-wrapper.properties -o .mvn/wrapper/maven-wrapper.properties
chmod +x mvnw
3. Pin a specific Maven version in the wrapper properties
Edit .mvn/wrapper/maven-wrapper.properties:
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
4. Verify the wrapper resolves the correct Maven version
./mvnw --version
Expected output:
Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcca2954f4f)
Maven home: /home/user/.m2/wrapper/dists/apache-maven-3.9.6-bin/...
Java version: 17.0.10, vendor: Eclipse Adoptium, runtime: /usr/lib/jvm/java-17-openjdk-amd64
5. Run a full build to confirm the wrapper works end to end
./mvnw clean install
Expected output:
[INFO] Scanning for projects...
[INFO] Building your-project 1.0.0
[INFO] BUILD SUCCESS
6. Check that wrapper files are tracked by Git
git status mvnw .mvn/
Expected output:
On branch main
nothing to commit, working tree clean
7. Troubleshoot "mvnw: Permission denied"
If you get Permission denied when running ./mvnw:
chmod +x mvnw
8. Troubleshoot "mvnw: /bin/sh^M: bad interpreter"
This happens when the file has Windows line endings (CRLF). Fix with:
sed -i 's/\r$//' mvnw
git add mvnw
9. Use the official Maven Wrapper plugin for Gradle projects too
If your project uses Gradle but you prefer Maven, generate the Maven wrapper alongside:
mvn wrapper:wrapper -Dmaven=3.9.6
./mvnw clean install
10. Verify the wrapper JAR is not corrupt
jar tf .mvn/wrapper/maven-wrapper.jar | head -5
Expected output:
META-INF/
META-INF/MANIFEST.MF
org/
org/apache/
org/apache/maven/
If the command fails, re-download the wrapper JAR.
Prevention
- Commit
mvnw,mvnw.cmd, and the.mvn/wrapper/directory to version control โ these are small text files that enable anyone to build without installing Maven - Run
mvn wrapper:wrapperbefore the first commit when creating a new project - Pin a specific Maven release version in the wrapper properties file to ensure reproducible builds
- Use
./mvnwin all build scripts and CI configuration instead of the systemmvncommand - Add the wrapper JAR (
maven-wrapper.jar) to.gitignoreโ it is downloaded automatically on first use and does not need to be tracked
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro