您的位置:首页 > 其它

maven 教程五 将项目发布到私服

2016-04-12 17:02 447 查看

1 . 修改私服中仓库的部署策略

Release版本的项目应该发布到Releases仓库中,对应的,Snapshot版本应该发布到Snapshots仓库中。Maven根据pom.xml文件中版本号<version>节点的属性是否包含-SNAPSHOT,来判断该项目是否是snapshot版本。如果是snapshot版本,在执行mvn deploy部署命令时,maven会自动将项目发布到Snapshots仓库。要发布项目,首先需要将Releases仓库和Snapshots仓库的“Deployment Policy”设置为“Allow Redeploy”:



2 . 配置项目的部署仓库

在pom.xml中分别对Release版本和Snapshot版本配置部署仓库,其中id唯一,url分别对应私服中Releases和Snapshots仓库的Repository Path:



<uniqueVersion>表示是否为Snapshot版本分配一个包含时间戳的构建号,效果如下:



<distributionManagement>
<snapshotRepository>
<id>user-snapshot</id>
<name>User Porject Snapshot</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
<uniqueVersion>true</uniqueVersion>
</snapshotRepository>
<repository>
<id>user-release</id>
<name>User Porject Release</name>
<url>http://localhost:8081/nexus/content/repositories/releases/</url>
</repository>
</distributionManagement>

3 . 启用Deployment用户

Nexus默认有三个用户,其中Deployment用户用于部署项目:



Deployment用户默认密码为deployment123,右键菜单可修改或重置密码:



settings.xml中分别为上面配置的部署仓库配置server,其中id需要分别对应上面的部署仓库id:

<servers>
<server>
<id>user-release</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>user-snapshot</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>

4 . 发布项目

右键pom.xml - Run As - 2 Maven build...



发布成功后,在私服的仓库中就能看到了:



5 . 在Nexus中手动上传项目构件

在Nexus仓库的Artifact Upload选项卡中,填写相关信息,可以手动的方式上传项目构件:



注:但是现在还是无法使用私服下载依赖,还需要配置如下内容在setting.xml 文件中:

<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<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>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>

OK,现在一个私服就搭建成功了。

原文链接:Maven入门指南⑥:将项目发布到私服
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: