Application of the snapshot library and release library in maven2, maven2snapshot

Source: Internet
Author: User

[Go to] Application of the snapshot library and release library in maven2, maven2snapshot

[Reprint statement] reprint must be noted: This article from Iron wood box blog http://www.mzone.cc
[Original address] Original Permanent address: http://www.mzone.cc/article/279.html

In the previous article, I introduced the differences and functions of the snapshot Library and the release library in maven2. Here I will introduce how to apply the snapshot and release libraries in the project, apply the snapshot and release libraries to release different versions in different environments. First, let's look at the definition of a pom file:

<project>    <modelVersion>4.0.0</modelVersion>    <groupId>cc.mzone</groupId>    <artifactId>myjar</artifactId>    <version>${project.release.version}</version>    <packaging>jar</packaging>     <distributionManagement>        <repository>        <id>mzone-release</id>        <url>http://192.168.1.88/nexus/content/repositories/mzone-release</url>        </repository>        <snapshotRepository>        <id>mzone-snapshot</id>        <url>http://192.168.1.88/nexus/content/repositories/mzone-snapshot</url>        </snapshotRepository>    </distributionManagement>     <properties>        <project.release.version>0.1-SNAPSHOT</project.release.version>    </properties>     <profiles>        <profile>            <id>product</id>        <properties>             <project.release.version>0.1</project.release.version>        </properties>        </profile>    </profiles></project>

First, we can see that the definition of version in the pom file is in the form of placeholders. The advantage is that version information can be replaced according to different profiles, for example, maven uses 0.1-SNAPSHOT by default as the version of this module.

1. If the mvn deploy-P product command is used during the release, version 0.1 is automatically used as the release version, and the snapshot and release rules are processed according to maven, because the version does not contain-SNAPSHOT, it is regarded as a formal release version and will be released to the release repository;

2. If the mvn deploy command is used at the time of release, the default version 0.1-SNAPSHOT will be used. In this case, maven considers the version as a SNAPSHOT and will be automatically released to the SNAPSHOT version library.

In the distributionManagement section, the addresses of the snapshot Library and the release library are configured. I use nexus as the backup server. For the version library, you can use mvn deploy to publish the configuration of id and url. Of course, if your image server requires a user name and password, in maven settings. make the following configurations in the xml file:

<servers>    <server>        <id>mzone-release</id>        <username>deployment</username>        <password>deployment</password>    </server>    <server>        <id>mzone-snapshot</id>        <username>deployment</username>        <password>deployment</password>    </server></servers>

Note that the server id configured here must be consistent with the id of the Repository corresponding to distributionManagement In the pom file, maven searches for the user name and password Based on the id to log on and upload and publish files when processing the release.

We can use the definition of profile to flexibly switch the snapshot version and the official release version of snapshot in the release. In the dependent components, we can also use profile to define the use of the snapshot library in the development phase, to use the official library function in the release phase, you only need to overwrite the default properties attribute values in different profiles.

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.