This is the fifth day of my participation in Gwen Challenge

background

When creating a project using Maven, the following files are generated by default.

├─.mvn │ ├─ ├─ MVNW ├─ MVNW ├─ mvnw.txtCopy the code

maven-wrapper

The traditional way to use Maven

  1. First go to the official website to download maven, and then configure the environment variable to add the MVN executable file path to the environment variable, so that you can use the MVN command directly later.
  2. In addition, the dependency files described in the project pom.xml file are downloaded in the repository directory of the.m2 file in the user directory by default.
  3. If you need to change the version of Maven, download Maven again and replace the Maven path in the environment variable path.

The purpose of maven – wrapper

Maven-wrapper was created to replace maven versions without having to do this manually:

  1. If you run MVNW (for example, MVNW clean), if there is no matching maven version, you will download maven directly and place it in the.m2/ Wrapper in the user directory
  2. The jar packages for the dependencies of the project will be placed directly in the repository directory of the project directory, so that the dependencies of the current project can be clearly seen.
  3. If you need to change the maven version, you only need to change the distributionUrl value of the. MVN /wrapper/maven-wrapper.properties property in the current project directory, and change the maven download address of the corresponding version. The MVNW command will automatically re-download Maven.

It can be said that the project with MVNW file, in addition to the additional need to configure the Java environment, only need to use the MVNW script of the project can complete compilation, packaging, publishing and a series of operations.

Personal understanding

  • Maven Wrapper can be downloaded automatically, but in fact most of our idea software comes with Maven.
  • If you are using an IDE, it is common practice to execute Maven commands directly using the Navigation Bar.
  • Maven Wrapper automatically switches maven versions based on configuration. This may seem useful, but the Maven version is actually quite stable. Rarely will you need to switch maven versions
  • Using the MVNW command will generate a repository directly under the current project. It looks like each project has its own repository, which is very modular. However, this not only wastes disk space, but also does not actually care about repository in development. Idea automatically has the External Librayies directory to view dependent JAR packages.

Maven-wrapper solves two problems

  1. You can specify a specific Maven version for a Java project, avoiding weird errors caused by version differences and unifying the project’s development environment
  2. There is no need to install Maven in advance, simplifying the configuration of the development environment