work offline / .repository / maven离线下载依赖

work offline / .repository / maven离线现在依赖

有时候我们想要使用本地maven仓库的依赖(即使用idea离线导入maven仓库的时候),导入不成功的错误,经过分析,发现不成功的文件夹里面存在lastUpdate后缀名的文件,删除该文件也未曾生效,依然会重新生成,后经过分析_remote.repositories文件。

在这里插入图片描述

.repositories 相当于本地maven仓库缓存了 jar/pom 的仓库中心,所以即使我们再修改maven配置文件的话,依然会去远程仓库下载依赖 。通过删除仓库中的_remote.repositories文件,解决由于更换仓库带来的jar包不兼容/重新下载问题

idea 离线导入maven仓库条件:
  • 那么我们需要在idea中,把work offline 设置为 true (false是去远程仓库中心去下载依赖)
  • 我们需要去本地仓库中 把 .repositories为后缀的文件给删除了。(确保你需要导入那个依赖,哪个依赖文件夹下的一定要删除)
  • 重新启动idea,然后点击maven的快捷键“reload all maven projects”
  • 有时候还需要再取消勾选“work offline”,把那些需要联网下载的依赖下载下来。

直接勾选下图这里,也可以把work offline 设置为 true;
在这里插入图片描述

_remote.repositories文件如下(junit jar包下)
junit-3.8.1.pom>nexus=

junit-3.8.1.jar>nexus=

junit-3.8.1.jar>central=

junit-3.8.1.pom>central=

maven的setting.xml配置如下

<mirrors>
	<mirror>
		<id>nexus</id>
		<mirrorOf>central</mirrorOf>
		<name>nexus</name>
		<url>http://maven.aliyun.com/nexus/content/groups/public</url>
	</mirror>
</mirrors>

通过我测试发现,我设置aliyun仓库的时候,会更新_remote.repositories为如下内容

junit-3.8.1.pom>nexus=

junit-3.8.1.jar>nexus=

如果我将aliyun仓库注释掉,默认使用外网maven仓库,此时_remote.repositories为如下内容

junit-3.8.1.pom>nexus=

junit-3.8.1.jar>nexus=

junit-3.8.1.jar>central=

junit-3.8.1.pom>central=

原来每次在更新maven项目的时候,每一个jar包路径下的_remote.repositories文件都会同setting.xml中设置的仓库地址id进行判断,如果没有匹配,会自动更新该jar包的相关文件,如果未联网则会出现jar无法发现的错误,导致即使jar存在,maven项目也无法使用该jar的情况。_

#Thu Jan 24 11:42:29 CST 2019
logback-parent-1.1.1.pom>nexus-aliyun=
logback-parent-1.1.1.pom>nexus-xx=
logback-parent-1.1.1.pom>mirror-all=
这里的nexus-aliyun表示setting.xml中配置的私服id

其中
这个文件存储的是每次从私服或者中央仓库下载的jar包的信息。
该logback-parent只有pom管理,所以没有jar

第3行:表示该pom第一次从nexus-aliyun(阿里云镜像)来的

第4行:表示更换远程仓库nexus-xx(xx私服)且该私服存在该pom,那么就将该私服地址写入到_remote.repositories.

第5行:表示镜像服务器mirror-all存在该pom

只有存在该资源的镜像或私服才会将私服或镜像的id写入到_remote.repositories中

参考资料:https://www.cnblogs.com/mySummer/p/9453777.html

假设我们更换了私服地址为nexus-abc,并且该私服不存在该资源,那么就会生成logback-parent-1.1.1.pom.lastUpdated文件;
也就是说,_remote.repositories文件,标示该资源的来源,如果你有这个_remote.repositories,那就会在访问本地的同时,必须确保远程上有才行(这里的远程是setting文件中配置的镜像或远程仓库,用id来进行关联,详情见标题2._remote…),否则就会报错;
参考资料:https://blog.csdn.net/zzb5682119/article/details/89217780
错误信息大体如下:

Could not resolve dependencies for project com-hallo-mybatis:generator:jar:1.0-SNAPSHOT: 
The following artifacts could not be resolved: com.tencent.tsf:spring-cloud-tsf-dependencies:pom:1.1.1-
RELEASE, com.tencent.tsf:spring-cloud-tsf-sleuth:jar:1.1.1-RELEASE, com.tencent.tsf:spring-cloud-tsf-
auth:jar:1.1.1-RELEASE: Failure to find com.tencent.tsf:spring-cloud-tsf-dependencies:pom:1.1.1-RELEASE in 
<span style="color:#ab4642">http://***:8081/repository/public/ was cached in the local repository, resolution 
will not be reattempted until the update interval of public has elapsed or updates are forced</span>

*._remote.和setting文件的py关系

<mirrors>
    <mirror>
      <!-- * 表示我这个镜像服务器要代替所有的仓库 -->
      <mirrorOf>*</mirrorOf>
      <name>mirror-all</name>
      <url>http://mirrors.cloud.tencent.com/nexus/repository/maven-public/</url>
      <id>custom</id>
</mirror>
<repositories>
     <repository>
         <id>central</id>
         <url>http://repo1.maven.org/maven2</url>
         <releases>
             <enabled>true</enabled>
         </releases>
         <snapshots>
             <enabled>true</enabled>
         </snapshots>
     </repository>
 </repositories>

_remote.repositories中 > 符号后的字符为setting文件中配置的mirror标签下的id,也就是镜像服务器的id(自己定义),也可以是repository标签下的id,表示远程仓库的id(自己定义);具体看本地仓库的构件是从哪里下载的。mirror标签下的id的权重大于repository标签下的id

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值