The construction of Maven private library nexus

Wang Zhaojun in winter 2021-05-04 14:46:40
construction maven private library nexus


1. Why use nexus

If there is no private service , All the components we need to go through maven The central warehouse and the third party Maven Warehouse download to local , And everyone in a team repeats from maven The download component of the warehouse undoubtedly increases the load of the warehouse and wastes the bandwidth of the external network , If the Internet is slow , It will also affect the progress of the project . In many cases, the development of the project is carried out in the intranet , Unable to connect to maven What about the warehouse ? How to develop common components for other projects to use ? At this time, we have to build our own team maven Private clothes , This will not only save the network bandwidth, but also accelerate the process of project construction , Of course, the precondition is that your private server has all the components needed for the project , Second, a little bit of large companies have their own internal architecture components , these jar The package will not be opened , Put it in nexus It's also a good choice

nexus Official website address

2. nexus install

2.1 Installation environment

Software environment brief introduction edition RAM
centos Linux operating system 7.8 8G
docker docker Virtualized environment 20.10.6
docker-compose docker Container arrangement 1.29.1

2.2 install nexus application

  1. newly build nexus Catalog
mkdir nexus
cd nexus
touch docker-compose.yaml
vim docker-compose.yaml
 Copy code 
  1. To configure docker-compose.yaml file
version: "3.7"
services:
nexus:
image: sonatype/nexus3
container_name: nexus
environment:
- "INSTALL4J_ADD_VM_PARAMS=-Xms1g -Xmx1g -XX:MaxDirectMemorySize=1g"
ports:
- 8764:8081
volumes:
- ./data:/nexus-data
restart: always
 Copy code 

matters needing attention

  • INSTALL4J_ADD_VM_PARAMS: Set up nexus Memory footprint , The default is 2g
  1. function docker-compose file
docker-compose up -d
 Copy code 

See done, Description installation complete

2.3 Connect nexus

visit http//:127.0.0.1:8764 appear nexus Visualization page

image.png The default account is :admin password :admin

image.png

2.4 Set up maven Private library connection

We set up domestic alicloud maven Source , By going nexus Acting on behalf of Alibaba cloud maven Source

image.png

  1. Set up alicloud warehouse agent
  • New warehouse , choice maven2(proxy), Enter the new warehouse page

image.png

  • Set the name , Proxy source address , Version type

Alibaba cloud maven Warehouse address :maven.aliyun.com/nexus/conte…

image.png

  • The new one is as shown in the figure

image.png

  1. Follow these steps , Set up maven Warehouse agent source
  2. Alibaba cloud maven After the warehouse and central warehouse source are set up , Continue to set the default maven-public Warehouse

image.png

image.png

  1. Here's the basic nexus End of warehouse setup for

3. Use nexus Warehouse

3.1 modify maven In the directory settings.xml file

As shown in the figure

image.png

  1. find localRepository label , Set what you need to store locally maven Warehouse directory , You can also not set it by default

image.png 2. find servers Node labels , Set up nexus Your account and password , Here we need to set up , because maven The project needs to read server Node account and password nexus Data connection for

image.png

<servers>
<server>
<id>maven-releases</id>
<username>admin</username>
<password>123456</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>123456</password>
</server>
</servers>
 Copy code 
  1. find mirrors Node labels , Set up maven Mirror source , This is the setup maven The mirror address of the warehouse

image.png

<mirrors>
<mirror>
<id>nexus-public</id>
<mirrorOf>central</mirrorOf>
<name>central repository</name>
<url>http://27.0.0.1:8764/repository/maven-public/</url>
</mirror>
</mirrors>
 Copy code 

The basis of setting is maven-public Warehouse connection address : image.png

3.2 Set up maven Project pom.xml file

3.2.1 Internal upload components pom structure

  1. add to distributionManagement node
<distributionManagement>
<repository>
<id>maven-releases</id>
<url>http://127.0.0.1:8764/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<url>http://127.0.0.1:8764/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
 Copy code 

id The label corresponds to the previous server In the label id Field

image.png 2. Add upload nexus To configure

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- resources Resource plug-ins -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
<encoding>UTF-8</encoding>
<!-- The suffix is pem、pfx Certificate file for -->
<nonFilteredFileExtensions>
<nonFilteredFileExtension>pem</nonFilteredFileExtension>
<nonFilteredFileExtension>pfx</nonFilteredFileExtension>
<nonFilteredFileExtension>p12</nonFilteredFileExtension>
<nonFilteredFileExtension>key</nonFilteredFileExtension>
<nonFilteredFileExtension>jks</nonFilteredFileExtension>
<nonFilteredFileExtension>db</nonFilteredFileExtension>
<nonFilteredFileExtension>txt</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
<!-- Configure source code package generation -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<!-- Compile the plug-in -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<!-- Resource plug-ins -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<!-- Configure source code package generation -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- packaged -P Parameters -->
<id>release</id>
<build>
<plugins>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>maven-releases</id>
<url>http://127.0.0.1:8764/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<url>http://127.0.0.1:8764/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
 Copy code 

snapshotRepository and repository Set the warehouse address you need to upload : image.png

  1. Here we are , Upload jar Package to maven Private bank nexus The configuration of is complete , Click on deploy Try it

image.png

3.2.2 Use nexus maven pom Set up

newly added repositories node , Connect nexus Specific warehouses

<repositories>
<repository>
<id>maven-releases</id>
<url>http://127.0.0.1:8764/repository/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>maven-snapshots</id>
<url>http://127.0.0.1:8764/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
 Copy code 

Here we are maven The private library can be used normally

4 summary

maven Private libraries play an important role in daily development , I hope my article here can give Xiaobai a little less step on the pit , Better work efficiency , Happy Fishing ~

版权声明
本文为[Wang Zhaojun in winter]所创,转载请带上原文链接,感谢
https://javamana.com/2021/05/20210504144300945i.html

  1. ASP调用SDK微信分享好友、朋友圈
  2. ASP calls SDK wechat to share friends and circle of friends
  3. SpringCloud(六)Bus消息总线
  4. 详解JavaScript中的正则表达式
  5. Springcloud (6) bus message bus
  6. Explain regular expressions in JavaScript
  7. Java 响应式关系数据库连接了解一下
  8. Java14它真的来了, 真是尾气都吃不到了
  9. 视频:使用Docker搭建RabbitMQ环境
  10. Java responsive relational database connection
  11. Java14 it's really coming. I can't eat the exhaust
  12. Video: building rabbitmq environment with docker
  13. SpringCloud(六)Bus消息总线
  14. 详解JavaScript中的正则表达式
  15. Springcloud (6) bus message bus
  16. Explain regular expressions in JavaScript
  17. Docker实战:用docker-compose搭建Laravel开发环境
  18. Docker: building laravel development environment with docker compose
  19. 求助,JAVA如何获取系统当前所有进程
  20. 有人用过JMeter或用HttpUnit写过测试吗????
  21. Help, Java how to get all the current processes of the system
  22. Has anyone ever used JMeter or written tests in httpUnit????
  23. Living in a mountain village in late spring
  24. Partridge day, spring of HKUST
  25. JavaScript异步编程4——Promise错误处理
  26. 海康摄像SDK开发笔记(一):海康威视网络摄像头SDK介绍与模块功能
  27. JavaScript asynchronous programming 4 -- promise error handling
  28. Haikang video SDK development notes (1): introduction and module functions of Hikvision webcam SDK
  29. JOP:用于FPGA的嵌入式实时系统中的Java优化处理器内核
  30. Spring Boot源码:使用MongoDB MongoTemplate公开REST在几分钟内实现CRUD功能
  31. Spring Boot应用程序事件教程 - reflectoring
  32. 带有Resilience4j断路器的Spring云网关 - rome
  33. 经验分享:Apache Kafka的缺点与陷阱 - Emil Koutanov
  34. 通过Spring Boot Webflux实现Reactor Kafka
  35. 从Java 8升级到Java 11应该注意的问题
  36. Jop: Java optimized processor core for FPGA embedded real time system
  37. Spring boot source code: use mongodb mongotemplate to open rest to realize crud function in a few minutes
  38. Spring boot application event tutorial - reflecting
  39. Spring cloud gateway with resilience4j circuit breaker - ROM
  40. Experience sharing: shortcomings and pitfalls of Apache Kafka - Emil koutanov
  41. Realization of reactor Kafka through spring boot Webflux
  42. RPC框架设计----Socket与I/0模型
  43. Problems in upgrading from Java 8 to Java 11
  44. RPC framework design -- socket and I / 0 model
  45. RPC框架设计----I/0模型
  46. RPC framework design: I / 0 model
  47. RPC框架设计----NIO编程缓冲区Buffer
  48. RPC框架设计----NIO编程缓冲区Buffer
  49. RPC framework design -- NiO programming buffer
  50. RPC framework design -- NiO programming buffer
  51. Java多线程基础
  52. Java multithreading Foundation
  53. 码农飞升记-00-Java发展历程
  54. Development history of coder-00-java
  55. 码农飞升记-00-Java发展历程
  56. Development history of coder-00-java
  57. Spring and Autumn Moon
  58. Node.js与Spring Boot比较? - Ryan Gleason
  59. Spring WebFlux的明显陷阱 - ŁukaszKyć
  60. Spring创始人Rod大叔对YAML的真实想法