Maven Learning Series (v)-Maven's Setting.xml detailed

Source: Internet
Author: User
2015/11/16


topic:maven< basic commands, setting.xml, precautions >


Points:localresponsity,plugingroups,server,mirror,profile,activeprofile


1 Basic commands
The difference between &LT;1&GT;MVN package,mvn INSTALL,MVN deploy
MVN Package Packaging
MVN install packaged and installed to a local library
MVN deploy package and install to remote library


Common
MVN Compile compilation
MVN Package dmaven.test.skip=true Skip Test compilation


<2> examples
EG1 generating the war package and deploying it into Tomcat
Mvn-pdev Clean Install-dmaven.test.skip=true
CD beauty-api-web/target/
RM-RF beauty-api-web/*
Unzip beauty-api-*.war-d Beauty-api-web
rm-rf/data/local/beauty-api/webapps/root/*
Cp-r beauty-api-web/*/data/local/beauty-api/webapps/root/


EG2 generate the war package and copy to the appropriate directory
MVN Clean Install-pdev-dmaven.test.skip=true
CD target
SCP Sogou-brandtask-*.jar Root@*.*.*.*:/data/task/task_online/sogou-brandtask.jar


2 pom file and Setting.xml file related knowledge points
<1>localresponsity Local Warehouse
Eg:<localrepository>e:/maven/repository</localrepository>


<2>plugingroups plug-in group, this element contains a series of plugingroup elements, each containing a groupid.
When a plugin is used and its groupid is not provided, the plugingroups list will be searched.
Eg:<plugingroups>
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>
Org.morbay.jetty:jetty-maven-plugin:run = mvn Jetty:run

<3>mirrors Mirroring
Eg: <mirrors>
<mirror>
<id>planetmirror.com</id>
<name>planetmirror australia</name>
<url>http://downloads.planetmirror.com/pub/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>


<4>server server, the user name of the server where the warehouse resides, password and other related information


<5>distributionmanagement dispenser with multiple warehouses, typically containing napshot and release warehouses


<6>profiles, including repositories,pluginrespositories,properties,activation
<<1 activation activated, if all specified conditions are reached, then activation is triggered and does not need to be fully reached at once
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>false</activeByDefault>
<jdk>1.5</jdk>
<os>
<name>windows xp</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
<property>
<name>mavenVersion</name>
<value>2.0.3</value>
</property>
<file>
<exists>${basedir}/file2.properties</exists>
<missing>${basedir}/file1.properties</missing>
</file>
</activation>
...
</profile>
</profiles>
When all of the above conditions are met, activate test


<<2 Properties Property
Eg:<profiles>
<profile>
...
<properties>
<user.install>${user.home}/our-project</user.install>
</properties>
...
</profile>
</profiles>
#如果这个profile被激活, then the attribute ${user.install} can be accessed, and the profile in the profiles
#需要激活才能使用, activation can be displayed via activation or-p

The <<3 repositories warehouse is a collection of remote projects that MAVEN uses to build a local repository for building systems. It comes from a local repository that Maven is called a plugin and relies on.
Different remote repositories contain different items, and when profile is activated, they will need to find a matching release or snapshot component.
Eg:<profiles>
<profile>
...
<repositories>
<repository>
<id>codehausSnapshots</id>
<name>codehaus snapshots</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http://snapshots.maven.codehaus.org/maven2</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
...
</pluginRepositories>
...
</profile>
</profiles>

<<4 plugin Repositorie plug-in warehouse, the warehouse contains two important types of artifacts. The first is the component that is used for other component dependencies, which is the majority of the plugins in the central repository.
Another type of widget is the plug-in pluginrepository element that points to a remote address where a new plug-in can be found.
<<5 Active Profiles Active profiles
Eg:<activeprofiles>
<activeProfile>env-test</activeProfile>
</activeProfiles>


3 precautions
The difference between snapshot and release in <1>maven
The warehouses in <<1 maven are divided into two types, snapshot snapshot warehouse and release publishing warehouse. The snapshot snapshot warehouse is used to save the unstable version during the development process.
The release official repository is used to store stable releases. Define a component/module as a snapshot version, just add-snapshot to the module's version number in the Pom file (must be capitalized)
<<2 Snapshot version mvn deploy is automatically published to the snapshot repository, without changing the version number, when the package is compiled directly,
MAVEN will automatically download the latest snapshot version from the mirror server. If it is a formal release, it will be automatically published to the official repository when MVN deploy.
With the formal version of the module, without changing the version number, the compilation package if the local already exists the version of the module will not be active to the mirror server download


<2>settings.xml exists in two places:
1. Place of installation: $M 2_home/conf/settings.xml
2. User's Directory: ${user.home}/.m2/settings.xml
The former is also called the global configuration, which is called the user Configuration. If both are present, their content will be merged and the user-scoped Settings.xml priority


<3> when profile in Setting.xml is activated, it overrides configuration information for the same ID in the POM


Application of snapshot Snapshot library and release release library in <4>maven2
Pom.xml
<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>
Setting.xml
<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>
1. If you use the MVN deploy-p Product command when publishing, you will automatically use 0.1 as the release version, and according to Maven's rules for handling snapshot and release,
Since the version number is not with-snapshot so as the official release version, will be released to the release warehouse;
2. If you use the MVN Deploy command when publishing, the default version number 0.1-snapshot will be used, and Maven will assume that it is a snapshot version and will be automatically published to the snapshot repository.
3, the Distributionmanagement section is configured in the snapshot snapshot library and release publishing library address, using the Nexus as the mirror server, the server's account and password stored
Placed in the server.

5 maven Cache issue.
Sometimes the. Repository cache file can be deleted because the MAVEN project cannot be updated.





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.