Docker 安装 Nexus3

1、创建 文件夹

mkdir -p /docker/nexus/nexus-data

chmod -R 777 /docker/nexus/nexus-data

2、启动脚本

vim start.sh

# 内容
docker rm -f nexus || true
docker run --name nexus \
-p 8081:8081 \
-v /docker/nexus/nexus-data:/nexus-data \
--restart=always \
-d sonatype/nexus3

3、访问

http://IP:8081 

4、仓库说明

默认仓库

        maven-central:maven中央库,默认从 https://repo1.maven.org/maven2/ 拉取jar

        maven-public:仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置 settings.xml 或项目 pom.xml 中使用

        maven-releases:私库发行版jar,初次安装请将Deployment policy设置为Allow redeploy

        maven-snapshots:私库快照(调试版本)jar

仓库类型    

        Hosted 宿主仓库:用户可以把一些自己的构件,deploy 到 hosted 中。

        Proxy 远程仓库的代理:比如说在Nexus中配置了 Central Repository 的 proxy,当用户向这个proxy请求一个构件时,这个proxy就会先在本地查找,如果找不到的话,再去远程仓库下载,返回给用户。相当于一个中转的作用。

        Group 仓库组:在 Maven 里没有这个概念,是 Nexus 特有,目的是将上述多个仓库聚合,对用户暴露统一的地址,这样用户就不需要配置多个地址,只要统一配置 Group 地址就OK了。

5、Maven 配置 settings.xml

 这里配置 pluginRepositories 的作用是让 maven命令需要的插件(比如clean、install都是maven的插件),也走 maven-public 去拉,而不是走中央仓库

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

	<profiles>
		<profile>
			<id>dev</id>
			<repositories>
				<repository>
					<id>local-nexus</id>
					<url>http://192.168.2.107:8081/repository/maven-public/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
			<pluginRepositories>
                <pluginRepository>
					<id>local-nexus</id>
					<url>http://192.168.2.107:8081/repository/maven-public/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
			    </pluginRepository>
            </pluginRepositories>
		</profile>
	</profiles>

	<activeProfiles>  
		<activeProfile>dev</activeProfile>  
	</activeProfiles>

	<servers>
		<server>
			<id>nexus-releases</id>
			<username>admin</username>
			<password>admin123</password>
		</server>
		<server>
			<id>nexus-snapshots</id>
			<username>admin</username>
			<password>admin123</password>
		</server>
	</servers>
	
</settings>

5、修改 项目里面的 pom.xml

# 配置私服发布地址,repository 里 id 需要和 maven 配置 setting.xml 里的 server id 名称保持一致

<distributionManagement>
	<repository>
		<id>nexus-releases</id>
		<name>Releases</name>
		<url>http://192.168.2.107:8081/repository/maven-releases/</url>
	</repository>
	<snapshotRepository>
		<id>nexus-snapshots</id>
		<name>Snapshot</name>
		<url>http://192.168.2.107:8081/repository/maven-snapshots/</url>
	</snapshotRepository>
</distributionManagement>

6、idea 中 发布

若项目版本号末尾带有 -SNAPSHOT,则会发布到snapshots快照版本仓库
若项目版本号末尾带有 -RELEASES 或什么都不带,则会发布到releases正式版本仓库

7、查看

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值