分布式项目Maven打包出现Could not resolve dependencies for project、Could not find artifact问题解决

在分布式项目中,通过模块化管理代码时遇到了打包失败的问题。具体表现为在student和teacher模块依赖common模块时,打包时无法找到common模块的jar包。解决方法是在common模块的pom.xml中添加<packaging>jar</packaging>,然后先在common模块执行clean和install,确保本地仓库有其jar包。最后在root模块执行clean和install,问题得到解决。

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

分布式项目中会用到多模块,就会形成父子工程,需要模块之间的依赖

我的模块分布式如下:

├── common                --公共资源模块
    ├── base                --返回类、编码枚举类
    ├── config              --公共配置
    ├── domain              --数据库映射对象
    ├── repository          --持久层接口
    ├── service             --业务层接口  
        ├── impl             --实体类  
    ├── utils               --工具  
    
├── student               --学生模块
    ├── repository          --持久层接口,继承公共模块持久层接口
    ├── service             --业务层接口,继承公共模块业务层接口
            ├── impl         --实体类
├── teacher               --教师模块
    ├── repository          --持久层接口,继承公共模块持久层接口
    ├── service             --业务层接口,继承公共模块业务层接口

在student、teacher模块中要依赖common模块
但是最近发现一个问题,虽然项目的各个模块能够运行,但是打包时却出现:
[ERROR] Failed to execute goal on project xxxx-student: Could not resolve dependencies for project com.xxxx:xxxx-student:jar:1.0-SNAPSHOT: Could not find artifact com.xxxx:xxxx-common:jar:1.0-SNAPSHOT -> [Help 1]

而后我又试了一下在root模块下clean再install,但是同样出现该问题

解决方案
在common模块的pom文件下
添加一行
<packaging>jar</packaging>

再在common模块下重新clean,install,确保本地仓库生成其jar包

重新再在root模块下clean,install,成功!

引用\[1\]:\[ERROR\] Failed to execute goal on project ssm_dao: Could not resolve dependencies for project org.example:ssm_dao:jar:1.0-SNAPSHOT: Could not find artifact org.example:ssm_utils:jar:1.0-SNAPSHOT -> \[Help 1\] 。 引用\[2\]:2、The repository you have configured requires authentication and Maven failed to provide the correct credentials to the server. In this case, make sure your ${user.home}/.m2/settings.xml contains a declaration whose matches the of the remote repository to use. See the Maven Settings Reference for more details. **2、你已经配置了请求权限给该库和maven不能提供正确的凭证(权限)给这个服务器–意思就是你配置的请求权限有问题。 举个例子:** 确保你的${user.home}/.m2/settings.xml该库的路径包含了 <server> 服务器的申明,并且该服务器的 <id>匹配你远程仓库的 <id>。如何引用maven的设置看如下: 。 引用\[3\]:安全和部署settings文件 1. <settings> 2. . 3. . 4. <servers> 5. <server> 6. <id>repo1</id> 7. <username>repouser</username> 8. <!-- other optional elements: 9. <password>my_login_password</password> 10. <privateKey>/path/to/identity</privateKey> (default is ~/.ssh/id_dsa) 11. <passphrase>my_key_passphrase</passphrase> 12. --> 13. </server> 14. </servers> 15. . 16. . 17. </settings> 。 问题:Could not resolve dependencies for project com.example 回答: 根据引用\[1\]的错误信息,这个问题是由于无法解析项目的依赖关系导致的。具体来说,错误信息中提到找不到artifact org.example:ssm_utils:jar:1.0-SNAPSHOT。根据引用\[2\]和引用\[3\]的内容,这个问题可能是由于Maven配置的权限问题导致的。你需要确保你的${user.home}/.m2/settings.xml文件中包含了正确的服务器声明,并且该服务器的id与远程仓库的id匹配。你还可以参考Maven的设置文档来获取更多详细信息。 #### 引用[.reference_title] - *1* [Could not resolve dependencies for project](https://blog.youkuaiyun.com/weixin_46809332/article/details/117339162)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [管理工具---Maven系列(一)编译问题Could not resolve dependencies for project](https://blog.youkuaiyun.com/wolf_love666/article/details/72625465)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值