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
- <repositories>
- <repository>
- <releases>
- <enabled>false</enabled>
- <updatepolicy>always</updatepolicy>
- <checksumpolicy>warn</checksumpolicy>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- <updatepolicy>never</updatepolicy>
- <checksumpolicy>fail</checksumpolicy>
- </Snapshots>
- <ID>codehaussnapshots</ID>
- <name>codehaus snapshots</name>
- <URL>https://repository-master.mulesoft.org/nexus/content/groups/public/</span ></url>
- <layout>default</layout>
- </repository>
- </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
- <distributionmanagement>
- <repository>
- <uniqueversion>false</uniqueversion>
- <ID>CORP1</ID>
- <name>corporate Repository</name>
- <URL>scp://repo/maven2</url>
- <layout>default</layout>
- </repository>
- <snapshotrepository>
- <uniqueversion>true</uniqueversion>
- <ID>propsnap</ID>
- <name>propellors snapshots</name>
- <URL>sftp://propellers.net/maven</url>
- <layout>legacy</layout>
- </snapshotrepository>
- ...
- </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