table of Contents
Use docker to build a private server
Add Alibaba Cloud Private Service Agent
Private server introduction
Private server is a special kind of remote warehouse. It is a warehouse service set up in the local area network. The private server acts as a proxy for the remote warehouse on the WAN for users in the local area network. When Maven needs to download a component, it requests it from the private server. If the component does not exist on the private server, it downloads it from an external remote warehouse, caches it on the private server, and then provides services for the Maven download request.
Benefits of private server
a. Save your own external network bandwidth
b. Speed up Maven build
c. Deploy your own internal third-party components
d. Improve stability and control
e. Reduce the load of the central warehouse.
Use docker to build a private server
One download mirror
docker pull sonatype/nexus3
Two create a data directory
mkdir -vp /opt/nexus/nexus-data && chown -R 200 /opt/nexus/nexus-data
Three start the container
docker run -d -p 8081:8081 --name nexus --restart=always -v /opt/nexus/nexus-data:/nexus-data sonatype/nexus3
Visit http://ip:8081, you can see the following page, the user name is admin, the initial password is inside the container /nexus-data/admin.password
You can use docker exec -it nexus /bin/bash to enter the container and get the login password.
Log in to the warehouse management page. We can see that maven2 has three types of warehouses.
1 proxy. The proxy proxy central warehouse, it can help us download the package from the remote warehouse to the local warehouse (additional Alibaba Cloud maven private server can be added as a proxy).
2 hosted. Local warehouse, used to store packages. There are beta and official versions
3 group. Custom warehouse combination can combine local warehouses and agent warehouses. The mirror source in the configuration file can configure this warehouse, which is relative to configuring the local warehouse and proxy warehouse.
Because the packages we upload are in the hosted warehouse, we need to configure the way that the package can be redeployed in the hosted warehouses, so that the 400 error will not be reported when repacking
Add Alibaba Cloud Private Service Agent
If you pull directly from the maven central warehouse, it will be very slow due to network reasons, and some jar package central warehouses may not be complete, so we can add a domestic maven private server as an agent. Here, we use Alibaba Cloud maven private server to add additional proxy downloads.
Click Create repository to add a repository
Remote storage Fill in the address of Alibaba Cloud's private server warehouse. Other configuration items are the same as those of the central warehouse.
After the configuration is complete, we also need to pull this warehouse into the warehouse group (group), so that the central warehouse and Alibaba Cloud private service warehouse can be used at the same time.
Configure settings.xml
Change the url to the address of your private server, and set the password you changed
<?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">
<activeProfiles>
<activeProfile>xxxxProfile</activeProfile>
<activeProfile>jdk-1.8</activeProfile>
</activeProfiles>
<localRepository>D:\maven_repository</localRepository>
<servers>
<!--maven私服账号,用于上传jar包到私服认证使用
注意,项目的pom.xml文件的
<distributionManagement>
<repository>
<id>releases</id>
<name>releases Repository</name>
<url>http://nexus.xxxx.info/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://nexus.xxxx.info/repository/maven-snapshots/</url>
<uniqueVersion>true</uniqueVersion>
</snapshotRepository>
</distributionManagement>
id必须于此保存一致,否则无法通过id找到对应的认证账号信息
-->
<server>
<id>releases</id>
<username>admin</username>
<password>xxxx</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>xxxx</password>
</server>
</servers>
<mirrors>
<mirror>
<id>releases</id>
<mirrorOf>*</mirrorOf>
<name>Nexus private</name>
<!--配置仓库为group类型的私服仓库地址-->
<url>http://nexus.xxxx.info/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>zhaodaoProfile</id>
<properties>
<encoding>UTF-8</encoding>
<project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
<project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>
</properties>
<repositories>
<repository>
<id>nexus</id>
<name>private nexus</name>
<!--配置仓库为group类型的私服仓库地址-->
<url>http://nexus.xxxx.info/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<!--配置仓库为group类型的私服仓库地址-->
<url>http://nexus.xxxx.info/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<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>
</profile>
</profiles>
</settings>
Configure the pom.xml file
In the pom.xml file of the project, the configuration is as follows
<distributionManagement>
<repository>
<id>releases</id>
<name>releases Repository</name>
<url>http://nexus.xxxx.info/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://nexus.xxxx.info/repository/maven-snapshots/</url>
<name>snapshots Repository</name>
</snapshotRepository>
</distributionManagement>
We can test through idea whether it can be packaged successfully.
test
Through the plug-in that comes with idea, click clean and deploy in turn. You can upload the local package to our private server
As you can see, our package has been uploaded to the private server.