一、问题描述

如下。相信大家平时在尝试自己搭建项目后执行 maven install 命令的时候偶尔会碰到这种问题,自己已经将<packing>为jar类型的模块已经安装到本地了,但在其他模块通过<dependency>标签引入时还是会报找不到的错误。

[INFO] Scanning for projects...
[INFO] 
[INFO] ------< com.example.baidu.speech.realtime:baidu-speech-realtime >-------
[INFO] Building baidu-speech-realtime 20240515
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/com/example/baidu/speech/common/baidu-speech-common/20240515/baidu-speech-common-20240515.pom
[WARNING] The POM for com.example.baidu.speech.common:baidu-speech-common:jar:20240515 is missing, no dependency information available
Downloading from nexus-aliyun: http://maven.aliyun.com/nexus/content/groups/public/com/example/baidu/speech/common/baidu-speech-common/20240515/baidu-speech-common-20240515.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.429 s
[INFO] Finished at: 2024-05-15T21:20:22+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project baidu-speech-realtime: Could not resolve dependencies for project com.example.baidu.speech.realtime:baidu-speech-realtime:jar:20240515: The following artifacts could not be resolved: com.example.baidu.speech.common:baidu-speech-common:jar:20240515 (absent): Could not find artifact com.example.baidu.speech.common:baidu-speech-common:jar:20240515 in nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException


二、问题解决

出现这种问题,需要检查你当前安装的这个模块在仓库中的坐标,与引入这个模块时的坐标是否一致。话不多说,直接上图。

2.1 比如下面这一张图,我要安装 baidu-speech-common 这个模块,但是呢作者比较手见,把下图中被注释了的<groupId>删掉了,这就导致 baidu-speech-common 这个模块它的<groupId>会默认继承<parent>中的<groupId>,也就是 com.example.baidu.speech,这也就意味着这个模块会被安装到 Maven 仓库中的 com/example/baidu/speech 目录下。

Mavne install 时报找不到依赖的问题_maven install 报错

2.2 接下来看这张图,我在 baidu-speech-realtime 模块中引入了 baidu-speech-common,然后在执行 maven install 的时候就报了上述问题(下图由于IDEA缓存原因没有爆红,其实控制台已经报错了)。引入的 baidu-speech-common 的<groupId>为 com.example.baidu.speech.common,也就是说当前模块需要去 Maven 仓库中的 com/example/baidu/speech/common 目录下寻找安装的模块。仔细对比上一张图的信息,会发现安装的模块坐标与要寻找的模块坐标不一致,这也就导致 mavne install 时报错说找不到依赖。

Mavne install 时报找不到依赖的问题_Maven_02