Maven 系列

Maven - 人生若只如初见(二)

2019-12-17  本文已影响0人  sunyelw

哪怕我不知道Maven的具体依赖加载顺序,我都敢肯定会先从本地仓库开始查找。

那么问题来了,我现在就碰到了这个有点颠覆我认知的问题,我本地仓库有一模一样的依赖,但打包就是打不进去!

下面是解决问题的定位过程,让我们开始这次冒险~


检查所有配置

1、pom
已知项目中手动把central给覆盖了

sunyelw@windows:user-cur-api$
sunyelw@windows:user-cur-api$ mvn help:effective-pom | grep -5 central
      <id>settings-profile-repo-01</id>
      <name>Repository for test settings-profile-repo</name>
      <url>http://www.myhost.com/maven/jdk18</url>
    </repository>
    <repository>
      <id>central</id>
      <name>ASIAINFO MIGU REPO</name>
      <url>http://10.1.228.195:18081/nexus/content/groups/public</url>
    </repository>
    <repository>
      <id>thirdparty</id>
--
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <build>
sunyelw@windows:user-cur-api$

2、setting.xml

sunyelw@windows:user-cur-api$
sunyelw@windows:user-cur-api$ mvn help:effective-settings
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building user-cur-api PACKT-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:effective-settings (default-cli) @ pinkstone-cur-api ---
[INFO]
Effective user-specific configuration settings:

<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Generated by Maven Help Plugin on 2019-12-17T09:37:51                  -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/                -->
<!--                                                                        -->
<!-- ====================================================================== -->

<!-- ====================================================================== -->
<!--                                                                        -->
<!-- Effective Settings for 'yello' on 'DESKTOP-S0L3088'                    -->
<!--                                                                        -->
<!-- ====================================================================== -->

<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">F:\repository</localRepository>
  <mirrors xmlns="http://maven.apache.org/SETTINGS/1.1.0">
    <mirror>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <id>alimaven</id>
    </mirror>
  </mirrors>
</settings>

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.958 s
[INFO] Finished at: 2019-12-17T21:37:52+08:00
[INFO] Final Memory: 16M/143M
[INFO] ------------------------------------------------------------------------
sunyelw@windows:user-cur-api$

思路1 - 本地缓存

查看本地缓存是否有问题,index.properties中会打印报错信息 (每个index文件夹都是一个仓库)

${USER_HOME}\.IntelliJIdea2017.3\system\Maven\Indices

没发现明显问题.

思路2 - 搜索顺序

首先分析jar包搜索顺序, 肯定是优先本地仓库的,找不到才会去各个文件中配置的仓库寻找

又进行了以下尝试

问题源头 - _remote.repositories 文件

先把问题 jar 包的 _remote.repositories 文件拎出来看看

#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Fri Nov 01 15:06:44 CST 2019
migu-metrics-1.0.2.pom>central=
migu-metrics-1.0.2.jar>central=

这个文件是做什么的?

为啥会加载不到?

解决方法

问题解决后的思考

既然这样, 那么走私服的依赖应该都有问题, 为啥只有这个 com.migu.tsg:migu-metrcs:1.0.2 依赖报错 ?

查看了下其他正常加载的 jar 包的 _remote.repositories文件

#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Tue Oct 22 10:18:07 CST 2019
pinkstone-api-PACKT-SNAPSHOT.jar>=
pinkstone-api-PACKT-SNAPSHOT.pom>=
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Fri Dec 21 17:16:30 CST 2018
gax-bom-1.35.0.pom>alimaven=

#NOTE: This is an Aether internal implementation file, its format can be changed without prior notice.
#Tue Jul 10 12:27:28 CST 2018
commons-lang-2.1.jar>alimaven=
commons-lang-2.1.pom>alimaven=
commons-lang-2.1.jar>central=
commons-lang-2.1.pom>central=

思考后解决方案

#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Fri Nov 01 15:06:44 CST 2019
migu-metrics-1.0.2.pom>=
migu-metrics-1.0.2.jar>=

当然,也可以删除全部此类文件

find ~/.m2/ -name _remote.repositories | xargs rm

_remote.repositories文件的作用到底是什么?

上一篇 下一篇

猜你喜欢

热点阅读