Maven学习(七):maven私服的使用

一、maven私服的结构

1、nexus仓库类型

1.1、hosted(宿主仓库)

部署自己的jar到这个类型的仓库,包括releases和snapshot两部分,Releases公司内部发布版本仓库、 Snapshots 公司内部测试版本仓库。

1.2、proxy(代理仓库)

用于代理远程的公共仓库,如maven中央仓库,用户连接私服,私服自动去中央仓库下载jar包或者插件。

1.3、group(仓库组)

用来合并多个hosted/proxy仓库,通常我们配置自己的maven连接仓库组。

1.4、virtual(虚拟)

兼容Maven1 版本的jar或者插件。

2、nexus仓库

  • central:代理仓库,代理中央仓库
  • pache-snapshots:代理仓库,存储snapshots构件,代理地址https://repository.apache.org/snapshots/
  • central-m1:virtual类型仓库,兼容Maven1 版本的jar或者插件
  • releases:本地仓库,存储releases构件。
  • snapshots:本地仓库,存储snapshots构件。
  • thirdparty:第三方仓库
  • public:仓库组

二、maven私服的使用

1、将项目发布到私服

1.1、在maven的配置文件settings.xml配置连接私服的用户和密码

1.2、在项目的pom.xml文件中配置私服仓库的地址

    <!--配置私服仓库的地址-->
    <distributionManagement>
        <repository>
            <id>releases</id>
            <url>http://localhost:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

2、从私服下载jar包

2.1、打开nexus配置仓库组,设置如下:

2.2、在maven的配置文件settings.xml配置仓库

	<profiles>
		<!-- 下载jar包配置 -->
		<profile>
			<!--profile的id -->
			<id>dev</id>
			<repositories>
				<repository> <!--仓库id,repositories可以配置多个仓库,保证id不重复 -->
					<id>nexus</id> <!--仓库地址,即nexus仓库组的地址 -->
					<url>http://localhost:8081/nexus/content/groups/public/</url> <!--是否下载releases构件 -->
					<releases>
						<enabled>true</enabled>
					</releases> <!--是否下载snapshots构件 -->
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
			<pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
				<pluginRepository> <!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
					<id>public</id>
					<name>Public Repositories</name>
					<url>http://localhost:8081/nexus/content/groups/public/</url>
				</pluginRepository>
			</pluginRepositories>
		</profile>
		<profile>    
			<id>jdk-1.8</id>    
			<activation>    
				<activeByDefault>true</activeByDefault>    
				<jdk>1.8</jdk>    
			</activation>    
			<properties>    
				<maven.compiler.source>1.8</maven.compiler.source>    
				<maven.compiler.target>1.8</maven.compiler.target>    
				<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>    
			</properties>     
		</profile>
	</profiles>

 2.3、激活使用profile定义的仓库,使之生效。

<!--激活使用profile定义的仓库-->
<activeProfiles>
	<activeProfile>dev</activeProfile>
</activeProfiles>

3、将第三方jar包放入私服

1、在maven的配置文件settings.xml中配置第三方仓库的server信息

<!--配置第三方仓库的server信息-->
<server>
	<id>thirdparty</id>
	<username>admin</username>
	<password>admin123</password>
</server>

2、执行安装第三方jar包到私服的命令

mvn deploy:deploy-file -DgroupId=项目的名称 -DartifactId=jar包名称 -Dversion=jar包版本 -Dpackaging=jar -Dfile=jar包所在目录及jar包文件名 -Durl=私服下载地址 -DrepositoryId=thirdparty

如:
mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=H:\Technology\Java\repository\fastjson-1.1.37.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty
发布了134 篇原创文章 · 获赞 10 · 访问量 7336

猜你喜欢

转载自blog.csdn.net/yu1755128147/article/details/104034734
今日推荐