Article Directory
Two methods of mixed use of private library and public library
maven setting.xml configuration:
A bunch of information on the Internet: https://www.cnblogs.com/hongmoshui/p/10762272.html
1. nexus proxy public library
It is also very common for nexus to build a private library. The detailed steps are Baidu.
The server where the private library is located is an Internet machine, so the configuration of setting.xml can be 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:\repository</localRepository>
<servers>
<server>
<id>myServer</id>
<username>admin</username>
<password>123456</password>
</server>
</servers>
<mirrors>
<mirror>
<id>my</id>
<mirrorOf>*</mirrorOf>
<name>my Repository</name>
<url>http://localhost:8081/repository/maven-group/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<repositories>
<repository>
<id>my</id>
<url>http://locahost:8081/repository/maven-public</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
</settings>
All mirrorOf
maven pull requests pass through the channel mirror
with the id configured above meiya
, and then the dependent pull will pull the warehouses in the mixed library one by one until the jar is pulled (mainly the mirrorOf
value here *
)
2. Setting.xml configures private and public libraries
In this case, the server where the private repository is located cannot be connected to the external network, so it is meaningless to configure the public repository agent at this time, but the development machine itself can be connected to the Internet.
In this case, the setting.xml configuration can be 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:\repository</localRepository>
<!-- <offline>true</offline>-->
<servers>
<server>
<id>myServer</id>
<username>admin</username>
<password>123456</password>
</server>
</servers>
<mirrors>
<mirror>
<id>my</id>
<mirrorOf>my</mirrorOf>
<name>central repository</name>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>my</id>
<url>http://localhost:8081/repository/maven-public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<!--默认节点,可以不配置,那么就会从maven中央仓库拉取-->
<profile>
<id>ali</id>
<repositories>
<repository>
<id>central</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
<activeProfile>ali</activeProfile>
</activeProfiles>
</settings>
It can be seen that this method configures an additional Alibaba Cloud warehouse. In fact, it can also be configured according to the first method, so here are a few knowledge points:
- After configuring
mirror
the node, it will pull dependencies from the custom mirror - How to judge which
mirror
node to go is based onmirrorOf
the attribute,mirrorOf
which corresponds torepository
the id, which can be configured: *, central, repositoryId, separated by multiple commas (you can check the detailed rules of mirrorOf online); - It also has a default pull situation. The premise of the default pull configuration is that the private warehouse mirror is
mirrorOf
not*
, otherwise all requests will go to*
the node, then there is no default pull situation, so:- On
mirrorOf
the node, configure the id of the private warehouse, and it will look for the private warehouse first. If the private warehouse cannot be found, it will go to the default maven central warehouse to find it; - Like the configuration above, when configuring a
central
warehouse with an id of , it means that it is a central warehouse. By default, this node is used. If we configure the warehouse of Alibaba Cloud above, then this warehouse will be used by default;
- On