原生Nexus包建立自己的Maven中央仓库及Docker快速安装Maven私服Nexus,两种方式对比,Docker爽

笔记搬家:在之前的项目中,项目有些额外的中央仓库没有的jar,所以项目决定搭建一个Maven的私服,下面记录搭建过程,自己在本地倒腾搭建了一个示例,方便以后有需要的时候参考【本地僵尸文件和笔记太多了,准备慢慢搬到博客】

Nexus2.x版本访问页面的URL是【而3.x没有nexus的后缀】:192.168.1.131:8081/nexus

当然这些仓库也可以不去自己建就使用自带的也可以,然后只建一个自己的第三方库即可(用来放中央仓库没有的jar

剩下的就是配置Mavensettings.xml或者配置工程的pom.xml文件,前者是一劳永逸,后者是每个工程都需要配置

Settings

<?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:\zMaven4Nexus\</localRepository>        

  <pluginGroups>
	<pluginGroup>org.sonatype.plugins</pluginGroup>
  </pluginGroups>

  <proxies>
  </proxies>

  <servers>
    <server>
      <id>mymaven-public</id>
      <username>hayashi</username>
      <password>hayashi</password>
    </server>

    <server>
      <id>mymaven-release</id>
      <username>hayashi</username>
      <password>hayashi</password>
    </server>

    <server>
      <id>mymaven-snapshot</id>
      <username>hayashi</username>
      <password>hayashi</password>
    </server>
  </servers>

  <mirrors>
	<mirror>
	   <id>mymaven-public</id>
	   <mirrorOf>*</mirrorOf>
	   <url>http://192.168.174.10:8081/repository/mymaven-public/</url>
     </mirror>
	
  </mirrors>

 
  <profiles>
	 <profile>
		 <!--profile的id-->
	    <id>hayashi-nexus</id>
	    <repositories>
			<repository>
				 <!--仓库id,repositories可以配置多个仓库,保证id不重复-->
				<id>mymaven-public</id>
				 <!--name非必须,随便-->
				<name>mymaven-public</name>
				 <!--仓库地址,即nexus仓库组的地址-->
				<url>http://192.168.174.10:8081/repository/mymaven-public/</url>
				 <!--是否下载releases构件,默认false-->
				<releases><enabled>true</enabled></releases>
				<!--是否下载snapshots构件,默认false-->
				<snapshots><enabled>true</enabled></snapshots>
			</repository>

			<repository>
				<id>mymaven-release</id>
				<name>mymaven-release</name>
				<url>http://192.168.174.10:8081/repository/mymaven-release/</url>
				<releases><enabled>true</enabled></releases>
				<snapshots><enabled>true</enabled></snapshots>
			</repository>

			<repository>
				<id>mymaven-snapshot</id>
				<name>mymaven-snapshot</name>
				<url>http://192.168.174.10:8081/repository/mymaven-snapshot/</url>
				<releases><enabled>true</enabled></releases>
				<snapshots><enabled>true</enabled></snapshots>
			</repository>
		</repositories>
		<pluginRepositories>
			<!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
			<pluginRepository>
				 <!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
				<id>mymaven-public</id>
				<name>mymaven-public</name>
				<url>http://192.168.174.10:8081/repository/mymaven-public/</url>
				<releases><enabled>true</enabled></releases>
				<snapshots><enabled>true</enabled></snapshots> 
			</pluginRepository> 
		</pluginRepositories>
  </profile>

  </profiles>
 
  <activeProfiles>
	 <!-- 使用profile定义仓库需要激活才能生效-->
    <activeProfile>hayashi-nexus</activeProfile>
  </activeProfiles>
</settings>

或者配置Pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>cn.ibm.test</groupId>
    <artifactId>A0TestNexus</artifactId>
    <version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>A0TestNexus</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>mymaven-public</id>
        <name>Nexus Repository</name>
        <url>http://192.168.174.10:8081/repository/mymaven-public/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    </repositories>
</project>

下面演示Docker安装Nexus2,那才是快,爽

Docker安装,参考:https://blog.csdn.net/weixin_42465125/article/details/87931405

注意:所有的容器在启动是如果没有指定数据卷挂载映射到主机的某个目录,当容器关闭或者宕机后,容器里面的数据会消失,所以一定要挂载

挂载本地目录映射容器的目录启动:

sudo docker run -d -p 8082:8081 -v /var/nexus-data:/sonatype-work --restart=always sonatype/nexus

补充内容:JD商家开放接口下载SDK包上传Nexus,Tmall的类似

参考:

https://blog.csdn.net/smartbetter/article/details/55116889

https://www.cnblogs.com/kevingrace/p/6201984.html
http://codeheaven.io/using-nexus-3-as-your-repository-part-1-maven-artifacts/

https://help.sonatype.com/repomanager3(官网文档)
https://help.sonatype.com/repomanager3/maven-repositories

https://www.xncoding.com/2017/09/02/tool/nexus.html(好文章)

可以使用Docker来安装部署(先要安装DockerDocker安装对Linux的内核有要求的),更简单https://blog.csdn.net/coutliuxing/article/details/78229407

 ********************************* 不积跬步无以至千里,不积小流无以成江海 *********************************

猜你喜欢

转载自blog.csdn.net/weixin_42465125/article/details/88742986