解决Downloading: http://repo.maven.apache.org/maven2/下载依赖

本文介绍了在使用Nexus作为 Maven 私服时,遇到依赖仍然从中央仓库下载的问题及解决方案。通过检查并修改 Maven 的 settings.xml 文件,将 repository 的 id 修改为 'central',确保所有请求都通过 Nexus 镜像进行,从而避免了依赖直接从 http://repo.maven.apache.org/maven2/ 下载。经过修改后,测试 mvn package 命令,成功从私服下载依赖。

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

问题描述:

最近发现使用nexus之后,居然有的依赖还是去http://repo.maven.apache.org/maven2/下载:

Downloaded from central: http://repo.maven.apache.org/maven2/...

那我配的私服岂不是白配了。

注意日志是从“central”这个id下载的,说明你的maven配置文件没有配置id为central的repository。

我一看,果然我写的nexus的repository的id是自定义的,不是central这个值。

问题解决:

直接改maven配置setting.xml,把repository的id改成central:

<settings>
<mirrors>
  <mirror>
  <!--This sends everything else to /public -->
  <id>nexus</id>
  <mirrorOf>*</mirrorOf>
  <url>你的nexus地址</url>
  </mirror>
</mirrors>
<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>你的nexus地址</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
      </repository>
  </repositories>
  <pluginRepositories>
      <pluginRepository>
      <id>central</id>
      <url>你的nexus地址</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>
</settings>

然后 mvn package测试,果然都去我私服下载了~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值