Maven tutorial (11) - Various configurations Maven remote repository

Original Address: https: //blog.csdn.net/liupeifeng3514/article/details/79545408

1, the remote repository configuration

In normal development, we often do not use the default central repository, the default speed access to the central warehouse slower, perhaps a lot of people visit, and sometimes can not meet the needs of our project, the project may require certain components of the central the warehouse is not, but there are other remote repository, such as JBoss Maven repository. In this case, in pom.xmlthe configuration of the warehouse, the code is as follows:

<!-- 配置远程仓库 -->
    <repositories>
        <repository>
            <id>jboss</id>
            <name>JBoss Repository</name>
            <url>http://repository.jboss.com/maven2/</url>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>daily</updatePolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
                <checksumPolicy>warn</checksumPolicy>
            </snapshots>
            <layout>default</layout>
        </repository>
    </repositories>

repository: Under repositories element, you can use the repository child element specifies one or more remote repository.

id: unique id warehouse declaration, in particular, need to note that, id Maven comes with central warehouse is central, if other warehouses statement also use the id, the configuration will cover the central warehouse.

name: name of the repository, let us know intuitively easy warehouses which, temporarily did not find other meanings too.

url: the address points to the warehouse, in general, are based on the address http protocol, Maven users can open the browser component warehouse address in the browser.

releases and snapshots: used to control the release Maven download rights for members and snapshots members. Note that enabled child element, this example releases of enabled is true, expressed open support JBoss warehouse version download release, and snapshots are enabled is false, meaning close JBoss warehouse snapshot version of the download support. According to this configuration, Maven will download the release from the JBoss warehouse components, rather than downloading a snapshot version of the component.

layout: element values ​​indicate default layout is the default layout of the warehouse and Maven3 Maven2, not Maven1 layout. The basic layout will not be used Maven1 of.

Other: For snapshots and releases, in addition to Enabled, which further comprises two additional sub-elements and updatePolicy checksumPolicy.

Maven updatePolicy element to configure the repository to check for updates frequency from a distance, the default value is dailyexpressed Maven checked once a day. Other useful values include: never- Never check for updates; always- check for updates every build; interval: X-update check every X minutes (X is an arbitrary integer).

ChecksumPolicy elements used to configure policy Maven check the checksum of the file. When the build is deployed to the Maven repository, will test and deploy the corresponding file. When downloading member, Maven file and verifies the checksum, the checksum if the verification fails, a default value when checksumPolicy warntime, Maven warning message is output when executed constructed, other available values comprises: fail-Maven encountered checksum error let the build to fail; ignore- Maven completely ignore the checksum error.

2, a remote warehouse certification

The most common remote repository can be accessed directly without authentication, but we tend to set up their own remote Maven repository in the usual development, for security reasons, we need to provide authentication information to access such remote repository. Configuring authentication information and configuring different remote repository, a remote repository can be directly pom.xmlconfigured, but you must configure the authentication information in the settings.xmlfile. This is because the pom tend to be submitted to the code repository accessible by all members, but settings.xmlusually only present in the machine. Thus, in settings.xmlthe configuration of authentication information more secure.

< Settings > 
     ... 
     <-! Configure Remote Authentication Information Warehouse -> 
     < Servers > 
         < Server > 
             < the above mentioned id > Releases </ the above mentioned id > 
             < username > ADMIN </ username > 
             < password > admin123 </ password > 
         </ Server > 
     </ Servers > 
     ... 
</ Settings >

The code above we configured a remote repository id for the certification of information releases. Maven uses settings.xmlfile serverselement and its children serverconfigure the warehouse authentication information. Authentication username is admin, the authentication password is admin123. The key here is the id element, settings.xmlthe serverelement idmust be pom.xmlin need of authentication repositoryelements idexactly the same. It is this id authentication information to the warehouse configuration linked together.

3, deployment artifacts to a remote repository

Our use of your own remote repository is to deploy our own project components as well as some of the components can not be obtained directly from the outside of the warehouse in a remote warehouse. So as to when developing for the other team members.

In addition to Maven can compile, test, package of the project, the project will also deploy generated artifacts to a remote warehouse. First, you need to edit the project pom.xmlfile. Configuration distributionManagementelements, as follows:

<distributionManagement>
        <repository>
            <id>releases</id>
            <name>public</name>
            <url>http://59.50.95.66:8081/nexus/content/repositories/releases</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Snapshots</name>
            <url>http://59.50.95.66:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
</distributionManagement>

distributionManagementContain repositoryand snapshotRepositorysub-elements, the former said warehouse release version (stable version) component, which represents a snapshot version (development test version) warehouse. These two elements need to be configured id, name and url, idto uniquely identify a remote repository, nameis to facilitate people to read, the key urlrepresents the address of the warehouse.

When deployed to a remote repository component, often require authentication, configure authentication methods above.

After the configuration is correct, run the command mvn clean deploy, Maven will build the project output component corresponding to the configuration deployed to a remote repository, the current version is a snapshot version if the project is to deploy a snapshot version of the address of the warehouse, otherwise deployed to the release version of the warehouse address.

The difference between a snapshot version and release version of Baidu access to information on your own.

4, configure the remote repository mirroring

If all the contents of the warehouse X can provide warehouse storage Y, then X can be considered to be a mirror image of Y. In other words, any member may be a Y obtained from the warehouse, it can be obtained from the mirror. For example, http://maven.oschina.net/content/groups/public/  central warehouse http://repo1.maven.org/maven2/  mirrored in China due to geographical factors, which can often mirror provide faster service than the central warehouse. Thus, the mirror can be disposed instead of using Maven central repository. Edit settings.xml, as follows:

<mirrors>
     <mirror>
      <id>maven.oschina.net</id>
      <name>maven mirror in China</name>
      <url>http://maven.oschina.net/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>

In this embodiment, mirrorOfthe Central value, expressed as a central repository of the mirror configuration, any request for a central repository will go to that image, the user can use the same method the other mirror configuration repository. idUnique identifier represents the mirror, namerepresents the name of the mirror, urlrepresents the address mirroring.

About a more common usage is mirrored in conjunction with PW. Since PW can represent any external public repository (including a central repository), and therefore, for Maven users within the organization, using a PW address is equivalent to the use of all the required external repository, which can be configured to concentrate PW, thereby simplifying Maven configuration itself. In this case, any required components are available from PW, PW is the mirror image of all warehouse. In this case, such a mirror can be configured:

<!--配置私服镜像-->
<mirrors> 
    <mirror>  
        <id>nexus</id>  
        <name>internal nexus repository</name>  
        <url>http://183.238.2.182:8081/nexus/content/groups/public/</url>  
        <mirrorOf>*</mirrorOf>  
    </mirror>  
</mirrors>

In this embodiment <mirrorOf>a value of the asterisk indicates that the configuration is a mirror image of all Maven repository, any request for a remote repository will be transferred http://183.238.2.182:8081/nexus/content/groups/public/ . If the mirror repository requires authentication, configure an id authentication information to the nexus.

It should be noted that, due to completely shield the warehouse mirror mirrored warehouse, the warehouse when the image is unstable or stop services, Maven will still be unable to access the image repository, and therefore will not be able to download components.

5, image repository available Maven

<mirror>
    <id>repo2</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://repo2.maven.org/maven2/</url>
</mirror>

<mirror>
    <id>ui</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://uk.maven.org/maven2/</url>
</mirror>

<mirror>
    <id>ibiblio</id>
    <mirrorOf>central</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>

<mirror>
    <id>jboss-public-repository-group</id>
    <mirrorOf>central</mirrorOf>
    <name>JBoss Public Repository Group</name>
    <url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>

<mirror>
    <id>JBossJBPM</id>
    <mirrorOf>central</mirrorOf>
    <name>JBossJBPM Repository</name>
    <url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
</mirror>

The above has been tested warehouse is accessible.

6, warehouse search service address

Sonatype Nexus:https://repository.sonatype.org/

MVNrepository:http://mvnrepository.com/

Search on dependent, personally I think that this is the best use of the two.

Conclusion: To get you have to pay, you have to learn to stick to pay, if you really find it hard, then you give up, but you give up, do not complain, the world really is balanced, I think life is so everyone is through their own efforts, to determine their own way of life.

 

Guess you like

Origin www.cnblogs.com/dyh004/p/11579586.html