MAVEN大白话笔记(三):maven在nexus私服上进行发布和下载
(一)setting.xml文件配置
配置servers:
<servers>
<server>
<id>releases</id> <!-- nexus私服配置的仓库id,releases通常是值正式版本库 -->
<username>developer</username> <!-- nexus私服里面配置的用户账号 -->
<password>123456</password> <!-- nexus私服里面配置的用户密码 -->
</server>
<server>
<id>snapshots</id> <!-- nexus私服配置的仓库id,snapshots通常是值开发版本库 -->
<username>developer</username>
<password>123456</password>
</server>
<servers>
这里的releases和snapshots是指nexus仓库的id,而username和password则是nexus仓库配置的用户id和密码。
这里就不叙述nexus的配置和使用了,想要了解的朋友可以看我写的一篇有关nexus简易使用的文章:https://blog.youkuaiyun.com/codeljy/article/details/81298866
配置profiles:
<profiles>
<profile>
<id>nexusProfile</id> <!-- profile的id,不能重复 -->
<repositories> <!-- 仓库组 -->
<repository> <!-- 一个仓库 -->
<id>public</id> <!-- 仓库的id -->
<url>http://localhost:8081/nexus/content/groups/public/</url> <!-- 仓库url -->
<snapshots>
<enabled>true</enabled> <!-- 能否使用开发版本库 -->
</snapshots>
<releases>
<enabled>true</enabled> <!-- 能否使用正式版本库 -->
</releases>
<layout>default</layout> <!-- 设置为default即可,具体有什么用,没研究过,知道得朋友欢迎在评论里面留言 -->
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexusProfile</activeProfile> <!-- 设置生效的profile -->
</activeProfiles>
(二)配置pom文件
配置distributionManagement:
<!-- 打包到私服的配置 -->
<distributionManagement>
<repository> <!-- 正式版本库 -->
<id>releases</id> <!-- 这里的id必须和你在setting.xml中配置的server的id保持一致 -->
<name>releases</name> <!-- 名称随意 -->
<url>http://localhost:8081/nexus/content/repositories/releases</url> <!-- 这是nexus私服对应的仓库地址url -->
</repository>
<snapshotRepository> <!-- 开发版本库 -->
<id>snapshots</id>
<name>snapshots</name>
<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
配置源码打包插件:
是否要打包源码,根据公司需要来决定。
<!-- 打包提交到私服时,把源码打上 -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
(三)执行打包部署命令
mvn clean deploy

(四)从nexus私服下载
加入依赖,然后Reimport一下maven就好了,前提是配置好setting.xml和pom文件。
若是eclipse则update一下maven即可。

本文详细介绍如何在Nexus私服中使用Maven进行项目构建、源码打包及部署。涵盖setting.xml与pom文件配置,以及如何从私服下载依赖。

被折叠的 条评论
为什么被折叠?



