This article mainly introduces the actual method of building Maven private servers and mirroring (pictures and texts). It is shared with you, as follows:
Preparation
Install Nexus for 3.6.*
theory
Nexus' repository types
Nexus built-in warehouse type
The following figure
Set up a private server process
Follow Step 2 to build a [testSnapshot] repository
Build a maven project and configure the following information in the POM file:
<distributionManagement> <repository> <id>releases</id> <url>http://192.168.0.1:8888/repository/testRelease/</url> </repository> <snapshotRepository> <id>Snapshots</id> <url>http://192.168.0.1:8888/repository/testSnapshot/</url> </snapshotRepository> <!-- Here url is the path to the repository --> </distributionManagement> <build> <plugins> <!-- JAR package plugin--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <configuration> <excludes> <exclude>**/*.properties</exclude> </excludes> </configuration> </plugin> <!-- Package source code plugin--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.0.1</version> <configuration> <attach>true</attach> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
Configure the setting file in maven, warehouse user account password
<servers> <id>release</id> <username>user</username> <password>123456</password> </server> <server> <id>Snapshots</id> <username>user</username> <password>123456</password> </server></servers>//The id here must be consistent with the id of the warehouse above
Enter the mvn command to package and upload
mvn clean source:jar packagemvn deploy -e
Check out Nexus’ [Components], as follows: Success
The reference is as follows, and the configuration is as follows in the pom.xml of the reference project
<!-- nexus private server configuration--><repositories> <repository> <id>nexus</id> <name>Nexus Repository</name> <url>http://192.168.2.20:8081/repository/java/</url> <releases> <enabled>true</enabled> </releases> <!--snapshots are turned off by default and need to be turned on--> <snapshots> <enabled>true</enabled> </snapshots> </repository></repositories><dependencies> <dependency> <groupId>com.example</groupId> <artifactId>utils</artifactId> <version>1.0</version> </dependency></dependencies>
Set up the mirror process
The setting configuration in Maven is as follows
<mirrors> <mirror> <id>mirror</id> <mirrorOf>*</mirrorOf> <name>Nexus aliyun</name> <url>http://116.62.220.224:8888/repository/testGroup/</url> </mirror> </mirror> <servers> <id>mirror</id> <username>user</username> <password>123456</password> </server> </servers>
In this way, all maven projects will reference dependencies from this image
Summarize
Mirroring is equivalent to intercepting and requesting forwarding, while private servers play the role of accelerating download construction and storing third-party construction, saving local maven configuration, etc. The combination of the two can fully reflect the advantages of maven.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.