首页 > 技术文章 > nexus私服搭建及信息配置

sxqjava 2019-07-09 17:02 原文

nexus私服搭建及信息配置

下载

登录nexus官网下载nexus安装包https://help.sonatype.com/repomanager2/download/download-archives---repository-manager-oss

  • 我一开始在官网上没有成功的将安装包下载下来,所以使用的nexus的war包

启动服务

  • 使用war包形式,将nexus的war包放在tomcat webapps目录下,启动tomcat即可。


访问nexus服务

第一次访问时,是匿名用户登录,只能看到部分权限,需要切换到admin用户,默认密码是admin123

setting.xml文件配置

<servers>
	<!-- 设置私库认证信息(访问) -->
	<server>
		<id>insuresmart-nexus</id>
		<username>admin</username>
		<password>admin123</password>
	</server>

	<!-- 设置私库认证信息(发布) -->
	<server>
		<id>insuresmart-nexus-releases</id>
		<username>admin</username>
		<password>admin123</password>
	</server>
	
	<server>
		<id>insuresmart-nexus-snapshots</id>
		<username>admin</username>
		<password>admin123</password>
	</server>
</servers>

<!--设置私库mirror 表示maven所有的请求都由nexus来处理 -->
	<mirror>
		<id>insuresmart-nexus</id>
		<name>Yitong Nexus Repository</name>
		<mirrorOf>*</mirrorOf>
		<url>http://localhost:8080/nexus/content/groups/public/</url>
	</mirror>
	
	<!--设置maven私库信息 -->
	<profile>
		<id>insuresmart-nexus</id>
		<repositories>
			<repository>
				<id>insuresmart-nexus</id>
				<name>insuresmart nexus repository</name>
				<url>http://localhost:8080/nexus/content/groups/public/</url>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
				<releases>
					<enabled>true</enabled>
				</releases>
			</repository>
		</repositories>
		<pluginRepositories>
			<pluginRepository>
				<id>insuresmart-nexus</id>
				<name>insuresmart nexus repository</name>
				<url>http://localhost:8080/nexus/content/groups/public/</url>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
				<releases>
					<enabled>true</enabled>
				</releases>
			</pluginRepository>
		</pluginRepositories>
	</profile>
	
	<!--覆盖maven中央仓库设置开启releases和snapshots版本的下载-->
	<profile>
		<id>central</id>
		<repositories>
			<repository>
				<id>central</id>
				<url>http://central</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
		</repositories>
		<pluginRepositories>
			<pluginRepository>
				<id>central</id>
				<url>http://central</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</pluginRepository>
		</pluginRepositories>
	</profile>
</profiles>


<!--激活私库信息的配置 -->
<activeProfiles>
	<activeProfile>insuresmart-nexus</activeProfile>
	<activeProfile>central</activeProfile>
</activeProfiles>

pom.xml文件配置

 <!--当前项目发布到远程仓库中-->
<distributionManagement>
    <repository>
        <id>insuresmart-nexus-releases</id>
        <name>insuresmart-nexus-releases</name>
        <url>http://localhost:8080/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>insuresmart-nexus-snapshots</id>
        <name>insuresmart-nexus-snapshots</name>
        <url>http://localhost:8080/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

标签id的值必须与setting文件中server标签中的值一致。

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

推荐阅读