Docker 安装 Maven 私服并配置
Docker 安装 Maven 私服并配置
1. 安装Maven
拉取镜像
docker pull sonatype/nexus3
创建挂载路径并分配权限
mkdir -p /home/nexus/nexus-data && chown -R 200 /home/nexus/nexus-data
运行容器
docker run -d -p 8087:8081 --restart=always --name nexus -v /home/nexus/nexus-data:/nexus-data sonatype/nexus3
查看默认密码
如果提示没有那个文件或目录,请多等一会,确定容器已经初始化成功,启动完成
cat /home/nexus/nexus-data/admin.password
2. 配置Maven
2.1 、进入管理界面

- Browse可以查看当前有多少仓库,搭建好的Nexus,默认会带有一些maven仓库,一般使用这些仓库就足够了。
- 默认仓库说明
 maven-central:maven中央库,默认从https://repo1.maven.org/maven2/拉取jar
 maven-releases:私库发行版jar,初次安装请将Deployment policy设置为Allow redeploy
 maven-snapshots:私库快照(调试版本)jar
 maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml或项目pom.xml中使用
- 仓库类型
      Group:这是一个仓库聚合的概念,用户仓库地址选择Group的地址,即可访问Group中配置的,用于方便开发人员自己设定的仓库。maven-public就是一个Group类型的仓库,内部设置了多个仓库,访问顺序取决于配置顺序,3.x默认Releases,Snapshots,                 Central,当然你也可以自己设置。
      Hosted:私有仓库,内部项目的发布仓库,专门用来存储我们自己生成的jar文件
      3rd party:未发布到公网的第三方jar (3.x去除了)
      Snapshots:本地项目的快照仓库
      Releases: 本地项目发布的正式版本
      Proxy:代理类型,从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage属性的值即被代理的远程仓库的路径),如可配置阿里云maven仓库
     Central:中央仓库
     Apache Snapshots:Apache专用快照仓库(3.x去除了)
2.2、增加新的代理源
第一步 按照步骤添加新的代理源

第二步选择添加maven2的代理

第三步添加代理(Cache统一设置为200天 288000)


第四步逐个增加常用代理
1. aliyun
https://maven.aliyun.com/repository/public
2. apache_snapshot
https://repository.apache.org/content/repositories/snapshots/
3. apache_release
https://repository.apache.org/content/repositories/releases/
4. atlassian
https://maven.atlassian.com/content/repositories/atlassian-public/
5. central.maven.org
http://central.maven.org/maven2/
6. datanucleus
http://www.datanucleus.org/downloads/maven2
7. maven-central (安装后自带,仅需设置Cache有效期即可)
https://repo1.maven.org/maven2/
8. nexus.axiomalaska.com
http://nexus.axiomalaska.com/nexus/content/repositories/public
9. oss.sonatype.org
https://oss.sonatype.org/content/repositories/snapshots
10.pentaho
https://public.nexus.pentaho.org/content/groups/omni/
11.google
https://maven.aliyun.com/repository/google
12.gradle-plugin
https://maven.aliyun.com/repository/gradle-plugin
13.spring
https://maven.aliyun.com/repository/spring
14.spring-plugin
https://maven.aliyun.com/repository/spring-plugin
15.grails-core
https://maven.aliyun.com/repository/grails-core
16.apache_snapshots
https://maven.aliyun.com/repository/apache-snapshots
第五步 设置maven-public 将这些代理加入Group,最好将默认的maven库放到最底下

第六步 设置私用仓库可重复发布
    Nexus安装后自带maven-releases,maven-snapshots两个仓库,用于将生成的jar包发布在这两个仓库中,在实际开发中需要将maven-releases设置为可以重复发布

2.3 、maven中的settings配置
记得将下方配置文件中的ip地址更改为你自己的
<?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>C:/tool/repository</localRepository>
  <pluginGroups>
  
  </pluginGroups>
  <proxies>
  
  </proxies>
  
	<servers>
		<server>
			<id>release</id>
			<username>admin</username>
			<password>admin123</password>
		</server>
		<server>  
			<id>snapshots</id>  
			<username>admin</username>  
			<password>admin123</password>  
		</server> 
	</servers>
  <mirrors>
    
	<mirror>
      <id>HolliParkMirror</id>
      <mirrorOf>*</mirrorOf>
      <name>HolliPark Repository Mirror.</name>
      <url>http://10.160.6.217:8087/repository/maven-public/</url>
    </mirror>
  </mirrors>
  <profiles>
	<profile>
		<id>HolliPark</id>
		<repositories>
			<repository>
			  <id>nexus</id>
			  <name>Public Repositories</name>
			  <url>http://10.160.6.217:8087/repository/maven-public/</url>
			  <releases>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
			  </releases>
			  <snapshots>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
			  </snapshots>
			</repository>
		  
			<repository>
			  <id>central</id>
			  <name>Central Repositories</name>
			  <url>http://10.160.6.217:8087/repository/maven-central/</url>
			  <releases>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
			  </releases>
			  <snapshots>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
			  </snapshots>
			</repository>
			
			<repository>
			  <id>release</id>
			  <name>Release Repositories</name>
			  <url>http://10.160.6.217:8087/repository/maven-releases/</url>
			  <releases>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
			  </releases>
			  <snapshots>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
			  </snapshots>
			</repository>
			
			<repository>
			  <id>snapshots</id>
			  <name>Snapshot Repositories</name>
			  <url>http://10.160.6.217:8087/repository/maven-snapshots/</url>
			  <releases>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
			  </releases>
			  <snapshots>
				<enabled>true</enabled>
				<updatePolicy>always</updatePolicy>
			  </snapshots>
			</repository>
		</repositories>
		  
	    <pluginRepositories>
		  <pluginRepository>
		    <id>plugins</id>
		    <name>Plugin Repositories</name>
		    <url>http://10.160.6.217:8087/repository/maven-public/</url>
		  </pluginRepository>
	    </pluginRepositories>
	</profile>
    
  </profiles>
</settings>
- 感谢你赐予我前进的力量
                        
                        
                            
 
            
        

 
                         
                         
                         
                         
                