Maven-repository (bottom), maven Repository

Source: Internet
Author: User
Tags sonatype sonatype nexus

Maven-repository (bottom), maven Repository
Maven-repository (bottom)
1. snapshot version

Any project or component in the Maven world has its own version. When Maven detects that the component is a snapshot version and the current component is not the latest version, it will be automatically updated. The Maven check cycle was mentioned before when the repository is configured in POM., <Repository>... <Snapshot> true... When the snapshot component is enabled, you can specify an updatePolicy In the snapshot tag. The default value is daily, that is, an update is detected every day. For more details, see the above.

To understand the significance of the snapshot version in actual scenarios: assume that A and B develop the two modules respectively, and B is highly dependent on the module developed by A. If there is no snapshot version, A generates A new version number after each update and uploads it in the Maven private server warehouse and every time Party B uses it, Party A should ask if there is the latest version. If so, Party B should update the version number of the dependency on component A in Project B to get the latest version. this is not only cumbersome, but may also fail to build B due to temporary negligence or other reasons. If you use the snapshot version, this problem can be well solved. The general process of Maven parsing the snapshot version is as follows: when project A defines Project A as A snapshot version, such as 1.0-snapshot, and then uploads it to the private server (component A must be successful before it can be published to the private server warehouse) when Maven detects that the version is a snapshot, it automatically stamps the component. For example, 1.0-20141101.142213-1 indicates the first snapshot at, January 1, November 1, 2014. With this timestamp, Maven can find the latest version of component modification in the repository at any time. In Project B's POM File Repository configuration, you only need to specify whether to enable the Snapshot mode and you can use updatePolicy. Maven will periodically check the latest version based on the specified update cycle. Once the latest version is available, it will be downloaded.

When the project needs to be released after a complete test, you can change the Snapshot version to the release version, for example, change 1.1-Snapshot to 1.1. This indicates that the version of this component is stable. We recommend that you do not use the snapshot version when referencing external components. Because of its instability, it is likely that the latest version is available, and the latest version and our component failure due to inconsistent requirements.


2. parse dependency from the Repository

When the local repository does not have the required dependencies, Maven will automatically download the latest snapshot version from the remote repository. When the dependent version is snapshot version, Maven will automatically download the latest snapshot version and Maven3 will no longer support it. in the plug-in, configure RELEASE and LASTEST. The essential reason is that this parsing policy may use an unstable version to cause component failure and the specific rules for Maven to parse Dependencies from the Repository:

1) when the scope of dependency is system, Maven directly parses the component from the local file system.

2) After the repository path is calculated based on the dependent coordinates, the resolution is successful if you try to find and find the component from the local repository directly.

3) if the local repository does not exist, if the dependent version displays the published version, that is, the stable version component has a specified version number, such as 4.1, 3.8, and so on.

4) if the previous version is SNAPSHOT, read the metadata groupId/artifactId/verion/maven-metatata.xml for all remote repositories based on the update policy, merge it with the local repository, get the latest SNAPSHOT version, check the local repository or download it from the remote repository.

5) if the snapshot version in the timestamp format is parsed, copy the timestamp format file to a non-timestamp format and use it.


3. Images

If warehouse X can provide all the content stored in warehouse Y, it can be considered that X is an image of Y. In other words, any component that can be obtained from Warehouse Y can be obtained from it. image. The image configuration is in settings. xml:

    <mirrors>        <mirror>            <id>mirrorId</id>            <mirrorOf>repositoryId</mirrorOf>            <name>Human Readable Name for thisMirror.</name>            <url>http://my.repository.com/repo/path</url>        </mirror>    </mirrors>

The key is mirrof, which specifies the ip address of the warehouse to be proxy, and this warehouse is also mentioned above. For example, the jboss repository we configured earlier, such as 6.4

    <repositories>        <repository>            <id>jboss-maven2-release-repository</id>            <name>JBoss Repository</name>            <url>http://repository.jboss.org/maven2/</url>            <layout>default</layout>            <!--<snapshots>-->            <!--<enabled>false</enabled>-->            <!--</snapshots>-->            <snapshots>                <enabled>true</enabled>                <checksumPolicy>ignore</checksumPolicy>                <updatePolicy>daily</updatePolicy>            </snapshots>            <releases>                <enabled>true</enabled>            </releases>        </repository>    </repositories>


Configure a proxy. If the proxy warehouse is a private server set up by ourselves (we usually use the private server to proxy all external remote warehouses) URL: http: // 192.168.1.8/content/repositories:

 

    <mirrors>        …        <mirror>            <id>nexus</id>            <mirrorOf> jboss-maven2-release-repository</mirrorOf>            <name>Mirror of jboss</name>            <url> http://repository.jboss.org/maven2/</url>        </mirror>        …    </mirrors>

To use a private server proxy for all remote repositories, you only need to change the <mirrorOf> jboss-maven2-release-repository </mirrorOf> to <mirrorOf> * </mirrof>.

More advanced image Configuration:

<MirrorOf> * </mirrorOf>: match all remote warehouses <mirrof> external: * </mirrorOf>: match all remote warehouses not on the local machine <mirrof> repo1, repo2 </mirrof>: Match repository repo1 and repo2, and use commas to separate Multiple Remote repositories. <MirrorOf> *,! Repo1 </mirrof>: Except for matching all remote repositories and repo1! Exclude remote repositories from matching.


4. Warehouse Search Service

When using Maven for daily development, when you know the name of the project and component to be used, you can search for its coordinates based on the name, and then use it in the project. Below are several common provides the repository search service URL:

1) Sonatype Nexus

Address: http://repository.sonatype.org/

2) Central Repository

Address: http://search.maven.org/#browse

3) MVNrepository

Address: http://mvnrepository.com/

4) jboss-maven2-release-repository (can be used, does not provide search function)

Address: http://repository.jboss.org/maven2/


Summary

Understand the concept of Maven repository, layout of Maven repository, the location of Maven repository, the concept of Maven local repository, remote repository, and central repository where to specify (% M2_HOME/lib/maven-model-builder-3.2.3.jar/org/apache/maven/model/pom. xml ). Understand repository configurations, how to configure remote repositories, and how to configure authentication information when authentication is required. Understand the meaning of the snapshot version and master the mechanism for parsing Dependencies from the repository (note the difference after Maven3 is that the plug-in configuration does not provide the RELEASE and LASTEST attributes) finally, the concept of the image, Master how to configure the image for the specified warehouse, or any warehouse.



How can I download all hibernate packages to a local repository through maven?

<Dependency>
<GroupId> org. hibernate </groupId>
<ArtifactId> hibernate-core </artifactId>
<Version> 4.1.7.Final </version>
</Dependency>
Write all the packages used
 
How can I build a maven repository without going online?

Copy the repository file from a previously connected machine to the local repository path. Generally, this path is $ home/. m2/repository.

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.