A library in Maven (repository) detailed---Repository remote libraries for configuring lookup artifacts such as. jar

Source: Internet
Author: User
Tags maven central

Ext: 52287856

A library (repository) in Maven is a collection of artifacts (artifact). Components are stored in a library in a certain layout.

The Libraries (repository) in Maven can be divided into local libraries and remote libraries. The local library is under the specified path on the computer where MAVEN is installed (typically, the. M2/repository in the user's home directory), and the artifacts in the local library are often downloaded to local parts of the remote library and referenced by the local project. Of course, when a local project is published, it is also published to the local library by default. Remote libraries are often provided by third parties and are used to publish artifacts for project downloads, such as the well-known Maven Central Library.

According to the use of components, the components can be divided into two categories, one is the component dependent on other components (dependencies), which is the main component of Maven library. The other is the plug-in (plugins), which is a special component. for dependent artifacts, the libraries in which they reside are set through <repositories> . However, for the plug-in component, due to the particularity of the plug-in, the plugin library is independent of the dependent library, using <pluginRepositories> separate settings. But because dependencies and plug-ins belong to artifacts, the settings in <repositories> and <pluginRepositories> are basically the same.

if a project needs to rely on a component, MAVEN compiles it first by looking for the widget from the local library. If not in the local library, then go to the remote library to find the widget, based on the configured remote library information.

If it is found in the remote library, it is downloaded to the local library and throws a compilation exception if none is in all remote libraries.

There are several ways in which you can configure a library in Maven. The most straightforward is in the Pom.xml file in the project, through the <repositories> configuration library, so that the configured library applies only to the current project. You can also configure special libraries in a specific environment through <repositories> in <profiles>, which can be implemented in the project's Pom.xml file or in Maven's settings.xml.

In addition, once a project is published, it is often deployed to a library as a component of the library for reference by other projects. Configure the libraries you want to publish through <repositories> in <distributionManagement>.

1. To set up <repositories> in Pom.xml or settings.xml, it is often necessary to provide a <repository> with the following information:

    • ID, ID of the library
    • Name, names of the libraries
    • URL, URL of the library
    • Layout, in Maven 2/3 is the default, only in Maven 1.x is the legacy
    • Releases, a component of version releases in the library
    • Snapshots, a component of version snapshots in the library

Depending on the version of the component, the component can be divided into releases types of components and snapshots types of components.

For a component, does the change in its version cause the widget to be updated in the library? You need to set the <releases> or <snapshots> of the library. The setup parameters for <releases> and <snapshots> are consistent as follows:

    • Enabled, whether updates are supported
    • Updatepolicy, Component Update policy, selectable values are daily, always, never, interval:x (where X is a number, representing the interval time, Unit min), the default is daily
    • Checksumpolicy, check code exception strategy, selectable values are ignore, fail, warn

Examples of defining <repository> in Pom.xml are as follows:

[HTML]View PlainCopy
  1. <repositories>
  2. <repository>
  3. <releases>
  4. <enabled>false</enabled>
  5. <updatepolicy>always</updatepolicy>
  6. <checksumpolicy>warn</checksumpolicy>
  7. </releases>
  8. <snapshots>
  9. <enabled>true</enabled>
  10. <updatepolicy>never</updatepolicy>
  11. <checksumpolicy>fail</checksumpolicy>
  12. </Snapshots>
  13. <ID>codehaussnapshots</ID>
  14. <name>codehaus snapshots</name>
  15. <URL>https://repository-master.mulesoft.org/nexus/content/groups/public/</span ></url>
  16. <layout>default</layout>
  17. </repository>
  18. </repositories>


2. <distributionmanagement> in Pom.xml;, responsible for managing the component's release packages and other build-generated support files.

You can also configure a <repository> in <distributionManagement>. The <repository> here shows the libraries published after the current project is deployed, as shown in the following example:

[HTML]View PlainCopy
  1. <distributionmanagement>
  2. <repository>
  3. <uniqueversion>false</uniqueversion>
  4. <ID>CORP1</ID>
  5. <name>corporate Repository</name>
  6. <URL>scp://repo/maven2</url>
  7. <layout>default</layout>
  8. </repository>
  9. <snapshotrepository>
  10. <uniqueversion>true</uniqueversion>
  11. <ID>propsnap</ID>
  12. <name>propellors snapshots</name>
  13. <URL>sftp://propellers.net/maven</url>
  14. <layout>legacy</layout>
  15. </snapshotrepository>
  16. ...
  17. </distributionmanagement>
The <repository> URL is the address published by the component of the current MAVEN project (but note that it may not be the address that accesses the widget).

A <snapshotrepository> can also be configured in <distributionManagement>, which represents the publishing library during development. The <snapshotRepository> settings are the same as <repository>. If <snapshotrepository> is not set, you can also use <repository> as <snapshotRepository>.

For specific usage of <distributionManagement> see subsequent articles.

3. <repositories> or <pluginrepositories> can be set in <profile> in Pom.xml or settings.xml, where < The repository> setting is the same as <repository> in <profile> settings <repositories>.

<repositories> in <profile> represents a library that is unique in this <profile> environment.

(go) a library in Maven (repository) detailed---Repository remote library for configuring lookup artifacts such as. jar

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.