Docker topic series 9: docker building and configuring maven private server Nexus

1, DOCKER builds MAVEN private server

1. Pull the image

docker pull sonatype/nexus3

2. Start the image

docker run -d -p 8081:8081 --name nexus sonatype/nexus3

3. Configure authentication information

In apache-maven-3.5 Settings under 3 \ conf XML

Find label

    <server>
      <id>nexus-releases</id>
      <username>admin</username>
      <password>12345678</password>
    </server>
    <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>12345678</password>
    </server>

In POM Configure warehouse address in XML

 <distributionManagement>
    <repository>
        <id>nexus-releases</id>
        <name>Nexus Releases Repository</name>
        <url>http://192.168.33.188:8081/repository/maven-releases</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <name>Nexus Snapshots Repository</name>
        <url>http://192.168.33.188:8081/repository/maven-snapshots</url>
    </snapshotRepository>
</distributionManagement>

Configure under subproject

<!--    Configure agent-->
    <repositories>
        <repository>
            <id>nexus</id>
            <name>Nexus Releases Repository</name>
            <url>http://192.168.33.9:8081/repository/maven-public/</url>
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>nexus</id>
            <name>Nexus Snapshots Repository</name>
            <url>http://192.168.33.9:8081/repository/maven-public/</url>
            <releases><enabled>true</enabled></releases>
            <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
    </pluginRepositories>

2, Configure MAVEN private server

Nexus

In the actual enterprise development process, all dependencies will be downloaded through private servers, and the corresponding Maven agent needs to be configured on Nexus

Create agent warehouse

At present, we only need to configure three necessary agent warehouses (aliyun nexus, spring household and spring snapshot). If you have other agent warehouses, the configuration process is the same as below

  • Log in to Nexus server
  • Click the settings button - > Repository - > repositories

  • Click Create Repository - > select Maven 2 (proxy) to create Maven proxy repository

  • Configure alicloud warehouse agent (version policy is Release)
    • Name: aliyun-nexus
    • Version pollcy: Release
    • Remote storate: http://maven.aliyun.com/nexus/content/groups/public/

  • Configure the Spring warehouse agent (the version policy is Release)
    • Name: spring-milestone
    • Version pollcy: Release
    • Remote storate: https://repo.spring.io/milestone

  • Configure Spring warehouse agent (version policy is Snapshot)
    • Name: spring-snapshot
    • Version pollcy: Snapshot
    • Remote storate: https://repo.spring.io/snapshot

  • After the three agent warehouses are created successfully, it is shown in the following figure

Configure agent warehouse

After the three agent warehouses are created, they cannot be used directly and need to be further configured

  • Click the settings button - > Repository - > repositories
  • Select Maven public and modify the Group as shown in the following figure (note the order)

Configure scheduled tasks

In the actual development process, a large number of snapshot versions may be generated every day. Each snapshot will occupy the corresponding space, and the historical snapshot version is meaningless. It should be cleaned regularly to release the occupied space resources. We can clean up the old snapshot version regularly through the Tasks plan task option.

  • Click > Settings > system > tasks
    - **Task name: ** `Delete SNAPSHOT`
    - **Repository: ** `(All Repositories)`
    - **Minimum snapshot count: ** `1`
    - **Snapshot retention (days): ** `0`
    - **Task frequency: ** `Manual`
    
    

Maven

Maven needs to be configured after Nexus configuration is completed. If anonymous access (operation after password modification) is prohibited when Nexus is started for the first time, permission verification is required when pulling dependencies, including deployment and other configurations.

Configure service authentication

  • Modify {your Maven directory} / conf / settings XML configuration file

  • modify

    <servers>
    

    element

    • id: unique identification (POM and mirror elements need to match)
    • username: Nexus login account
    • Password: Nexus login password
<servers>
    <server>
        <id>nexus-public</id>
        <username>admin</username>
        <password>12345678</password>
    </server>
    <server>
        <id>nexus-releases</id>
        <username>admin</username>
        <password>12345678</password>
    </server>
    <server>
        <id>nexus-snapshots</id>
        <username>admin</username>
        <password>12345678</password>
    </server>
</servers>

Configure mirror warehouse

  • modify

    <mirrors>
    

    element

    • id: it needs to match the id in the server element
    • mirrorOf: can be filled in central or * (all dependencies are downloaded through private servers)
    • name: whatever
    • url: warehouse address
<mirrors>
    <mirror>
        <id>nexus-public</id>
        <mirrorOf>*</mirrorOf>
        <name>Nexus Public</name>
        <url>http://nexus.funtl.com/repository/maven-public/</url>
    </mirror>
</mirrors>

Keywords: Java Docker Maven

Added by minifairy on Tue, 04 Jan 2022 20:18:11 +0200