Docker installs Nexus to build Maven private server and introduction


foreword

Building a private maven warehouse is suitable for collaborative work, such as: Project A is the company's toolkit, and project B will introduce the jar package formed after A install, but do other colleagues have to do the same operation as you when running locally? Is the same operation required to run online? Therefore, the jar packages generated by this type need to be managed in a unified place. You only need to push the jar package deployment of A to the private maven warehouse, and the project B can introduce dependencies in the pom file.


1. What is Nexus?

Official website: https://help.sonatype.com/repomanager3
Nexus is a very popular 仓库管理系统tool for managing and distributing various software packages, dependencies, build artifacts, etc. It is a Java-based open source software originally developed by Sonatype and released under the Apache license. In software development, it is often necessary to use a large number of code bases and third-party dependencies, which may come from different sources. Nexus can help developers in a unified place 管理所有的依赖项, making the process of project development more efficient and standardized.

Two, Docker installation method

1. Pull the image

docker pull sonatype/nexus3:latest

2. Create a mount directory

mkdir /data/nexus-data
chown -R 200 /data/nexus-data

3. run

docker run -d -p 8081:8081 --name nexus \
--restart=always \
-e INSTALL4J_ADD_VM_PARAMS="-Xms512m -Xmx512m \
-XX:MaxDirectMemorySize=1200m" \
-v /data/nexus-data:/nexus-data sonatype/nexus3

4. Container running log (optional)

# -f 实时追加最新日志
# --tail=N 查看日志的最后 N 行

docker logs -f --tail=100 nexus

After the startup is successful, the browser ip+port access will enter the main page:

3. User login

The account of nexus3 is:admin

The password is to check a file called admin.password in the directory to be mounted, which contains the login password of admin.

cd /data/nexus-data

查看密码
cat admin.password

After logging in, change the password according to the prompts and you can use it normally.

4. Warehouse introduction

insert image description here

There are three types of nexus warehouses:

  1. proxy proxy warehouse, such as proxying to the maven central warehouse.
  2. hosted Host warehouse, that is, your own private warehouse.
  3. group Warehouse group, composed of multiple warehouses, when downloading dependencies, 遍历each warehouse will find them.

Among them, the hosted host warehouse is divided into: releases and shapshots, which respectively represent the release version and snapshot version of the dependent version. Snapshot dependencies cannot be uploaded to release repositories, and vice versa. Nexus made restrictions.

There are two warehouse formats:

  1. maven2 (concern)
  2. nuget

The default group warehouse group puts the three warehouses of central, releases and shapshots into it
insert image description here

5. Create a proxy warehouse

insert image description here
insert image description here
insert image description here

https://maven.aliyun.com/nexus/content/groups/public

6. Upload dependencies (emphasis)

1. First configure the setting.xml of the local maven

<servers>
  <!-- 这是配置访问私有仓库的用户名密码 -->
  <server>
    <!-- id标签可以随便填,唯一即可 -->
    <id>opals-maven</id>
    <username>dev</username>
    <password>dev</password>
  </server>
</servers>

2. Add in the module pom.xml configuration that needs to be uploaded

<distributionManagement>
   <repository>
       <id>opals-maven</id>
       <url>http://ip:port/repository/maven-releases/</url>
   </repository>
   <snapshotRepository>
       <id>opals-maven</id>
       <url>http://ip:port/repository/maven-snapshots/</url>
   </snapshotRepository>
</distributionManagement>

The repository tag is for uploading the release version
snapshotRepository tag is for uploading the snapshot version

  • Nexus will automatically select according to the version of the module. If your version number has a SNAPSHOT such as: <version>1.0.0-SNAPSHOT</version>, then it will be uploaded to the SNAPSHOT warehouse. The same is true for release. If the version number does not exist these two words, such as <version>1.0.0</version>, then the release warehouse will be selected. upload.
  • id, which is the server id configured above, nexus will use this id to go to the server to get the username and password to access the private server warehouse.
  • url, which is the address of the corresponding warehouse: just copy the url of the warehouse, pay attention to the corresponding warehouse

insert image description here

insert image description here

注意

insert image description here

Setting it to Allow redeploy means that we are allowed to maintain and upgrade the new version of the dependencies in the warehouse. If it is set to disable redeploy, it means that we cannot upload the upgraded version.

7. Download dependencies

1. Configure local maven, open setting.xml, and find the mirrors tag.

Then add a mirror tag:

<mirrors>
	<mirror>
	    <id>opals-maven</id>
	    <mirrorOf>*</mirrorOf>
	    <url>`仓库组`的url/</url>
	</mirror>
	
	<mirror>
	    <id>nexus-aliyun</id>
	    <mirrorOf>central</mirrorOf>
	    <name>Nexus aliyun</name>
	    <url>https://maven.aliyun.com/nexus/content/groups/public</url>
	</mirror>
</mirrors>

insert image description here


common problem

1. How to add the newly created warehouse to the group?

insert image description here
insert image description here

2. What does Nexus agent warehouse status mean?

online-remote availableIndicates that the proxy warehouse is available

online-ready to connectIndicates that there is no dependency to access the proxy warehouse. Nexus does not know whether the proxy warehouse can be used, so it can only be displayed as a pending connection state:

3. Pushing to Nexus prompts 405, what is the problem?

Return code is: 405, ReasonPhrase: PUT.

Check whether the configuration in the pom file <id></id><url></url>is correct, make sure it is deployed to hostedinstead of group
insert image description here

Guess you like

Origin blog.csdn.net/weixin_45549188/article/details/130213190