When I created a Spring Boot application I could see mvnw
and mvnw.cmd
files in the root of the project. What is the purpose of these two files?
2.1.mvnw: it's an executable Unix shell script used in place of a fully installed Maven. mvnw. cmd: it's the Batch version of the above script. mvn: the hidden folder that holds the Maven Wrapper Java library and its properties file.
It depends, if you want to use the Maven wrapper or not. If not, then you can delete those files. If you want to use it, then you have to commit the files in the repository, otherwise it doesn't make sense to use it.
The Maven Wrapper is an easy way to ensure a user of your Maven build has everything necessary to run your Maven build.
The . mvn directory is a directory where you can put some Maven configuration files. One of these Maven configuration files is the jvm. config file which can be used to configure the Java VM that is used by Maven to build your project.
These files are from Maven wrapper. It works similarly to the Gradle wrapper.
This allows you to run the Maven project without having Maven installed and present on the path. It downloads the correct Maven version if it's not found (as far as I know by default in your user home directory).
The mvnw
file is for Linux (bash) and the mvnw.cmd
is for the Windows environment.
To create or update all necessary Maven Wrapper files execute the following command:
mvn -N io.takari:maven:wrapper
To use a different version of maven you can specify the version as follows:
mvn -N io.takari:maven:wrapper -Dmaven=3.3.3
Both commands require maven on PATH
(add the path to maven bin
to Path
on System Variables) if you already have mvnw in your project you can use ./mvnw
instead of mvn
in the commands.
Command mvnw
uses Maven that is by default downloaded to ~/.m2/wrapper
on the first use.
URL with Maven is specified in each project at .mvn/wrapper/maven-wrapper.properties
:
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip
To update or change Maven version invoke the following (remember about --non-recursive
for multi-module projects):
./mvnw io.takari:maven:wrapper -Dmaven=3.3.9
or just modify .mvn/wrapper/maven-wrapper.properties
manually.
To generate wrapper from scratch using Maven (you need to have it already in PATH
run:
mvn io.takari:maven:wrapper -Dmaven=3.3.9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With