Use Docker to build a Nexus (maven) private warehouse, suitable for small team development in the company

For the installation of Docker, you can read the following article

Complete docker uninstallation and docker installation_Li Bai’s blog of coding-CSDN blog

Installation of nexus3

Pull the nexus3 image

docker pull sonatype/nexus3

 Create a shared folder between the container and the host

  1. mkdir -p /home/nexus/data

  2. chmod 777 -R /home/nexus/data

 Boot image

docker run -d --name nexus3 -p 8081:8081 --restart always -v /home/nexus/data:/nexus-data sonatype/nexus3

After the installation is complete, open the browser and visit http://1.2.3.4:8080/

Check the default password of nexus3

cat /home/nexus/data/admin.password

Default warehouse description

maven-central: Maven central library, which pulls jars from https://repo1.maven.org/maven2/ by default
maven-releases: private library release jar, first time During installation, please set the Deployment policy to Allow redeploy
maven-snapshots: private library snapshot (debug version) jar
maven-public: warehouse grouping, group the above three The warehouses are combined together to provide external services, which are used in the local maven basic configuration settings.xml or project pom.xml

 Introduction to Nexus warehouse types 

hosted: local warehouse, usually we will deploy our own components to this type of warehouse. For example, the company's second-party library.
proxy: proxy warehouse, they are used to proxy remote public warehouses, such as maven central warehouse.
group: Warehouse group, used to merge multiple hosted/proxy warehouses. When your project wants to use resources in multiple repositories, you don’t need to reference them multiple times. You only need to reference one group. Can.

Nexus warehouse

 Check which library sources are in the group

 Create proxy proxy warehouse

 Select maven2 (proxy), proxy warehouse

 

 Remote warehouse address

  1. Alibaba Cloud's maven central warehouse address: http://maven.aliyun.com/nexus/content/groups/public/

  2. Apache's maven central warehouse address: http://repo.maven.apache.org/maven2/

 

 

 Create a hosted hosting warehouse

Hosted has three methods: Releases, Snapshot, Mixed
 
Releases: Usually a released Jar package
Snapshot: an unreleased version a>
Mixed:mixed

 

 

Create group group warehouse

 

 Maven configuration

The relationship between the setting.xml file under Maven and the pom.xml file in the project is: the setting.xml file is a global setting and is used first, while the pom.xml file is a local setting. If the mirror address is not configured in the pom.xml file, it will be searched according to the address defined in setting.xml.

Modify the local maven setting.xml file as follows:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
	<!-- 构建系统本地仓库的路径 -->
    <localRepository>D:\temp\apache-maven-3.8.5\repository</localRepository> 
   
   <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

<!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
 
  </proxies>
 
  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
   
  <servers>
    <!-- 配置本地仓库访问私服的权限  nexus的 登录用户名密码 -->
      <server>
        <id>My_group</id>
        <username>admin</username>
        <password>123456</password>
      </server>

      <server>
        <id>My_hosted</id>
        <username>admin</username>
        <password>123456</password>
      </server>

      <server>
        <id>My_proxy</id>
        <username>admin</username>
        <password>123456</password>
      </server>
  </servers>
   
      

     <!-- 配置本地仓库资源来源 -->
     <mirrors>
        <mirror>
	      <!--配置仓库组的ID-->
          <id>My_group</id>
	      <!--*代表所有内容都从私服获取-->
          <mirrorOf>*</mirrorOf>
	      <!--私服仓库组maven-public的访问路径-->
          <url>http://1.2.3.4:8080/repository/My_group/</url>
        </mirror>
     </mirrors>
  
  
  
  <profiles>
      <!-- 属性列表配置 -->
      <profile>
        <id>maven_profile</id>
        <properties>
          <maven.compiler.source>1.8</maven.compiler.source>  
          <maven.compiler.target>1.8</maven.compiler.target>  
          <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
        </properties>

        <!-- 远程仓库列表 maven用来填充构建系统本地仓库所使用的一组远程仓库 -->
        <repositories>
          <repository>
            <id>My_proxy</id>
            <url>http://1.2.3.4:8080/repository/My_proxy/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
          </repository>
 
          <repository>
            <id>My_hosted</id>
            <url>http://1.2.3.4:8080/repository/My_hosted/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
          </repository>
 
      </repositories>
 
    <pluginRepositories>
      <pluginRepository>
        <id>My_group</id>
        <url>http://1.2.3.4:8080/repository/My_group/</url>
      </pluginRepository>
    </pluginRepositories>
    
    </profile>
  </profiles>

  
  
 <!-- 激活所使用的配置-->
  <activeProfiles>
   <activeProfile>maven_profile</activeProfile>     
  </activeProfiles>

   
</settings>

After modification, you can recompile the project (pom file location cmd). You must add the parameter -U, (-U, --update-snapshots to force the update of releases, snapshots type plug-ins or dependent libraries, otherwise Maven will only update snapshot dependencies once a day. ). The proxy warehouse will download the jar package from the remote central warehouse

mvn clean compile -U
 

 If the compilation fails, it is usually because the central warehouse of the jar package used by the project does not exist. You can manually submit it to the My_hosted host warehouse.

mvn deploy:deploy-file -DgroupId=dm.jdbc.driver -DartifactId=DmDriver7-18 -Dversion=7.6.1.142 -Dpackaging=jar -DpomFile=D:\DmDialect7-18-5.0.pom  -Dfile=D:\DmDialect7-18-5.0.jar -Durl=http://1.2.3.4:8080/repository/My_hosted/ -DrepositoryId=My_hosted

Command explanation:

Local warehouse directory structure: repository\dm\jdbc\driver\DmDriver7-18\7.6.0.142

-DgroupId=dm.jdbc.driver                                                                        <                       credule -Dversion=7.6.1.142 Custom version number -Dpackaging=jar The type passed is jar type -Dfile=D:\DmDialect7-18-5.0. jar The local disk location of the jar package



-DpomFile=""D:\DmDialect7-18-5.0.pom"" The local disk location of the Pom file of the jar package
-Durl=http://1.2 .3.4:8080/repository/My_hosted/ The address of the hosted resource library
-DrepositoryId=My_hosted It needs to be consistent with the ID configured in the setting.xml file

 Structure after uploading

 Compile again and it will be successful

 

At this time, you can see that the agent warehouse has downloaded the jar package required for project compilation from the central warehouse. Similarly, you can also see all jar packages in the group warehouse, including the proxy warehouse and the host warehouse.

 

 There is another way to upload the local jar package to the hosted host repository

 

 After the upload is successful, you can see that the newly uploaded third-party jar package is already in the hosted repository and group repository. 

At this point, nexus is configured as a private server warehouse. Another point is to deploy the jar package to the private server. This choice is based on everyone's situation. I don't need it here at the moment. I will add it later if you need it. thank you all!​  

                                                                                                             white

Guess you like

Origin blog.csdn.net/qq_46264836/article/details/129671876