maven repository and mirror

This article is for learning record "maven real" book key knowledge points, too flawed or not the description of the proposed purchase to read the original book

This article relates to some of the maven repository and mirror some simple concepts

Brief introduction

For maven, the warehouse only divided into two categories, local warehouses and remote repository . maven priority rule is to find a local warehouse, local warehouse if not, then begins the remote repository is acquired. If they are not, then error.
Relatively large number of cases, maven will be because of the network, while the warehouse is not downloaded to the jar package, and only .jar.lastupdate, and .pomthese two documents. The view pom.xml file when no error will. So long you need to delete the local repository, directory of this package, download it again.

PW is also a remote repository, PW purpose is to save network bandwidth, and the structures in a LAN server maven.

Local Warehouse

When no local maven modify the configuration, the default will be the current user directory .m2/repository/under a local warehouse. There is a settings.xml file in the conf maven installation directory, you can set the path to the local warehouse.

<settings>
    <localRepository>D:/maven/maven-repository/</localRepository>
</settings>

Note that , in fact, there is a settings is only for the current user, that is .m2/settings.xml, but this is generally xml file does not exist, the need to create their own hand. The settings file in the conf directory, is a global setting is for all users.

Remote repository

Local warehouse like our own study, we are looking for a book to go in his study, he found no, so long is go to a bookstore or go online to buy. In maven world, bookstore or online store, you can be seen as a remote repository.
Remote repository using relatively large number of central warehouse (also the default warehouse) , in addition to some remote repository such as Jboss, specifically to be set according to the actual situation of the project.
maven default central warehouse, if you need to use other warehouses, the need to be similar to the following configuration in pom.xml

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

Note inside the snapshot is false, said they did not download a snapshot release from the warehouse. Because the snapshot is constantly changing, and we actually use the bag, often they want to be stable, so for our engineering terms is relatively safe.

Update the remote repository

A label with the snapshot there is a similar effect is release, the download of the release. The default is true. The snapshot and release these two labels, has two sub-elements.

<snapshots>
    <enabled>true</enabled>
    <updatePolicy>daily</updatePolicy>
    <checksumPolicy>ignore</checksumPolicy>
</snapshot>

updatePolicy representation method to check for updates, the default is updated once a day, other values include never Never check for updates; always check for updates when each building; interval X, every x minutes check again
checksumPolicy is directed to the check and, when the file when deployed to a remote warehouse, it will generate a checksum file, somewhat similar to a digital signature, to represent the file has not been modified. When maven downloads will be verified according to the checksum file, If the check fails, it will be to decide whether to warn the basis of this property. They said they did not ignore the warning, and warn indicate give a warning when building, but fail to make representation to build into a failure.

Remote repository certification

Generally, we would like PW own internal publicity is built, then some PW warehouse may not apply to other sectors, then there will be an account password authentication. This configuration information is present in the settings.xml. It is worth noting that the inside of the id, id you need and configuration in pom.xml to be consistent.

<servers>
    <server>
        <id>my-proj</id>
        <username>repo-my</username>
        <password>123123</password>
    </server>
</servers>

Deployed to the remote repository

Pom.xml file in the project, needs to be configured, and this configuration is distributionManagementthe element.

<distributionManagement>
    <repository>
        <id>proj-my</id>
        <name>123</name>
        <url>http://xxx</url>
    </repository>
    <snapshotRepository>
        <id>proj-my</id>
        <name>123</name>
        <url>http://xxx</url>
    </snapshotRepository>
</distributionManagement>

snapshotRepository represents a snapshot version to be published address of the warehouse. This is a general need to be carefully deployed, and certified configuration is said above-mentioned.
Time really to be deployed on the implementation mvn clean deploycan be.

Snapshot version

Just think, there are two departments because of an urgent task requires cooperation, working two departments need to expand at the same time, the work required to publish their own function code to PW warehouse within the LAN to go. If there is no mechanism maven snapshot, it may each time one of the department released a version, then you need to notify other departments, the pom.xml file version number to be modified.
Obviously, this is a very troublesome thing.
Snapshot version to be solved is like this, you may frequently published version, but do not need to modify the pom.xml of the situation. In the process of publishing the PW's, maven snapshot will automatically be replaced, time-stamped. Then another department, during the time of acquisition, can be obtained according to the latest time stamp of the file, the default is to check once each execution.
Version snapshot should be used only inside the organization or dependencies between modules, because the snapshot version is very unstable, it may be time to build today, but by tomorrow will not work.

Dependency resolution

  • When the system is dependent on the range, the analyzing unit directly from the local file system
  • Calculated based on the path-dependent coordinate warehouse, first try to find a local, not local, remote from the warehouse to get
  • In the case of a local warehouse does not exist
    • If the dependent is a member of the release version, such as 1.2.1 or 1.2.-beta-1 that is convenient for all remote repository, find the download.
    • LATEST RELEASE or if it is, it is based on the updated policy, read all remote metadata repository groupId/artifactId/version/maven-metadata.xml, merge with the local repository metadata corresponding to obtain the true value of LATEST or RELEASE
    • If SNAPSHOT, read all remote metadata repository groupId/artifactId/version/maven-metadata.xml, merging the metadata corresponding to the local repository, to obtain the true value of the SNAPSHOT
    • If the component version is a snapshot of the last parsed timestamp format (eg 1.4.1-20191101.121403-3), then copy the file timestamp format to non-timestamp format. As SNAPSHOT.

Mirroring

The role of mirror and cdn very similar, because the relationship between the GFW, many foreign warehouse access is very slow or inaccessible, then you can make use of mirrored address some of the country's few large companies to accelerate download files, personal use of more Ali is a mirror image of the address.

<mirrors>
   <mirror>
        <id>alimaven</id>
        <mirrorOf>central</mirrorOf>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
    </mirror>
</mirrors>

Guess you like

Origin www.cnblogs.com/westlin/p/10993368.html