nexus的使用(1)

本文详细介绍了如何通过Nexus与Maven的setting.xml文件配置实现本地仓库管理,包括镜像配置、仓库激活及项目构件部署等操作,并提供了具体的pom.xml与setting.xml配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下内容参考于:http://blog.youkuaiyun.com/mexican_jacky/article/details/50275695

nexus在Maven配置文件(setting.xml)常用的设置为:

(1)

 <profiles>
<profile>
      <id>nexus_Repository</id>
       <repositories>
  <repository>
  <id>nexus</id>
  <name>nexus is Repository</name>
  <url>http://localhost:8081/nexus/content/groups/public/</url>
  <!-- 默认就是true -->
  <releases>
  <enabled>true</enabled>
  </releases>
  <!-- 默认是是false,需手动打开 设置为true -->
  <snapshots>
  <enabled>true</enabled>
  </snapshots>
</repository>
  </repositories>
    </profile>   
  </profiles>
<!-- 这里必须激活profile 才能生效 -->
  <activeProfiles>
    <activeProfile>nexus_Repository</activeProfile>
  </activeProfiles>

 这种方式在nexus服务器停止的了,maven有会从maven的中央工厂mvnrepository进行下载,

这是因为,Maven项目首先回去nexus中去找,当它发现nexus服务停止这个时候它就回去找Maven的工厂。

(2)配置镜像:

<mirrors>
   
    <mirror>
      <id>mirrorNexusId</id>
      <!-- *号代表所有工厂镜像 ,当Maven进来之后,不管什么工厂都回去找URL的地址去下载 -->
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://localhost:8081/nexus/content/groups/public/</url>
    </mirror>
  </mirrors>
<!-- 这里的工厂配置,是Maven中的,起snapshots是false,我们可以通过这种方式将其激活,就可以访问中央工厂中snapshots -->
  <profiles>
<profile>
      <id>nexusRepository</id>
      <repositories>
   <repository>
     <id>central</id>
     <name>Central Repository</name>
     <url>https://repo.maven.apache.org/maven2</url>
     <layout>default</layout>
     <snapshots>
       <enabled>true</enabled>
     </snapshots>
   </repository>
 </repositories>
    </profile>   
  </profiles>
<!-- 这里必须激活profile 才能生效 -->
  <activeProfiles>
    <activeProfile>nexusRepository</activeProfile>
  </activeProfiles>

 

当我们发现Nexus服务停止了就不能下载,而只能从Nexus中下载,这是推荐的作法。这意味这mirrors覆盖了profile的使用。因为任何url都指向mirrors。

(3)当需要把项目增加到nexus时,需如下配置:

以下内容参考于:http://juvenshun.iteye.com/blog/349534

pom.xml:

<project>  
...  
<distributionManagement>  
  <repository>  
    <id>nexus-releases</id>  
      <name>Nexus Release Repository</name>  
      <url>http://127.0.0.1:8080/nexus/content/repositories/releases/</url>  
  </repository>  
  <snapshotRepository>  
    <id>nexus-snapshots</id>  
    <name>Nexus Snapshot Repository</name>  
    <url>http://127.0.0.1:8080/nexus/content/repositories/snapshots/</url>  
  </snapshotRepository>  
</distributionManagement>  
...  
</project>  

 setting.xml

<settings>  
...  
<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>  

这里我们配置所有的snapshot版本构件部署到Nexus的Snapshots仓库中, 所有的release构件部署到Nexus的Releases仓库中。由于部署需要登陆,因为我们在settings.xml中配置对应Repository id的用户名和密码。

然后,在项目目录中执行mvn deploy ,你会看到maven将项目构件部署到Nexus中,浏览Nexus对应的仓库,就可以看到刚才部署的构件。当其他人构建其项目时,Maven就会从Nexus寻找依赖并下载。

 

转载于:https://www.cnblogs.com/pingqlin341/p/7229656.html

### Nexus 3.30.1 使用指南 #### 安装和运行 对于Nexus 3.30.1的安装过程,需先访问官方资源页面完成下载工作[^1]。一旦文件被成功获取到本地环境之后,则依照平台差异(Linux, Windows 或 MacOS),遵循特定的操作指引来执行安装程序。 启动服务前确认Java环境已正确定位并满足最低版本需求。通过命令行或者图形界面的方式激活应用,初次加载期间会经历初始化设置流程,此阶段建议保持网络连接稳定以便顺利拉取必要的更新组件。 #### 用户界面概览 进入管理后台后,默认展示的是仪表盘视图,这里提供了整体系统的健康状态监控以及快捷操作入口。左侧导航栏集成了主要功能模块链接,包括但不限于浏览存储库、创建新项目、调整全局参数设定等选项。 #### 配置Maven使用私服 为了使构建工具能够识别私有仓库地址,在`settings.xml`中添加如下片段: ```xml <mirrors> <mirror> <id>nexus</id> <url>http://localhost:8081/repository/maven-public/</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>central</id> <url>http://localhost:8081/repository/maven-central/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>http://localhost:8081/repository/maven-central/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> ``` 上述配置使得所有依赖项查询请求都将优先转发至指定的内部源服务器处理,从而实现加速下载速度及控制对外暴露程度的目的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值