What MVNW is (Maven wrapper/maven Keep build tool version always tools)

Source: Internet
Author: User

Background

Maven is a very popular Java project building software, it sets the project's dependency management, test case running, packaging, component management in one, is a good helper of our work, MAVEN rapid development, and its distribution is more and more, if our project is based on the MAVEN component, So how can we ensure that the Maven version of the colleague who gets our project source is the same as the version we developed, maybe you think it's simple, a company that requires all colleagues to use a maven version? Within an organization this is possible, what if you open up a project? How to ensure that the MAVEN version you use is consistent with the MAVEN version of the person who downloaded your source, and that's when MVNW.

The MVNW full name is maven Wrapper, which works by documenting the MAVEN version you want to use in the Maven-wrapper.properties file, and when the user executes the MVNW clean command, discovers that the current user's Maven version and expected version are inconsistent. Then download the desired version and use the desired version to execute the MVN command, such as the mvn clean.

Adding MVNW support to a project is simple, in two ways:

Method One: Add the plugin declaration in Pom.xml:

<plugin>    <groupId>Com.rimerosolutions.maven.plugins</groupId>    <Artifactid>Wrapper-maven-plugin</Artifactid>    <version>0.0.4</version></plugin>

This will help us generate Mvnw.bat, MVNW, Maven/maven-wrapper.jar, and maven/maven-wrapper.properties files when we execute MVN wrapper:wrapper.

Then we can use MVNW instead of the MVN command to execute all MAVEN commands, such as MVNW clean

Method two: Direct execution of goal (recommended use of this)

Mvn-n io.takari:maven:wrapper-dmaven=3.3.3 says the version of Maven we expect to use is 3.3.3

The resulting content is the same as the first, except that the directory structure is different, Maven-wrapper.jar and maven-wrapper.properties in the ". Mvn/wrapper" Directory

Precautions for use

1, because we use the new maven, if your settings.xml is not placed in the current user under the. M2 directory, then the execution MVNW will not read your original settings.xml file

2. In Mvnw.bat, there is a script as follows: if exist "%m2_home%\bin\mvn.cmd" Goto init, This means that if mvn.cmd is found, the initialization operation is performed, but the earlier version of MAVEN is not called Mvn.cmd, but is called mvn.bat, so it will be reported as "Error:m2_home is set to an invalid directory" error, It would be nice to change your local maven matching suffix.

Test Project: Https://github.com/easonjim/5_java_example/tree/master/mvnw/testproject

Reference:

Https://github.com/takari/maven-wrapper (official website)

http://www.javacoder.cn/?p=759 (the above content is transferred from this article)

What MVNW is (Maven wrapper/maven Keep build tool version always tools)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.