You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven依赖添加失败:无法将项目作为依赖引入其他项目

无法将本地Maven项目作为依赖引入其他项目

问题详情

  1. 目标项目已执行mvn clean install并构建成功(附构建成功截图)
  2. 在另一项目的pom.xml中添加如下依赖配置后,无法正常引入该依赖:
<dependency>
<<group ID>com.consumer</groupId>
<<artifact ID>socket consumer</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

(附依赖配置截图、其他相关截图)

已尝试的无效解决方案

  • 更新Maven依赖:确认pom.xml配置后,在IntelliJ IDEA中通过View->Windows Tool->Maven窗口重新加载/导入依赖
  • 在IntelliJ IDEA中执行File->Invalidate Caches / Restart...并选择Invalidate and Restart
  • 命令行重新执行mvn clean install构建目标项目
  • 按下Alt+Enter无任何提示信息

相关代码片段

目标项目Java代码片段

@RestController
@RequestMapping("/api/producer")
public class ProducerController {

    @Autowired
    private SimpMessagingTemplate messagingTemplate;
    private UserAuditRepository userAuditRepository;

    private static final Logger logger = LoggerFactory.getLogger(ProducerController.class);


    @Autowired
    public ProducerController(UserAuditRepository userAuditRepository) {
        this.userAuditRepository = userAuditRepository;
    }

    @GetMapping("/send-message")
    public ResponseEntity<String> sendMessageToUser() {
        logger.info("Sending message to all users");

        UserAudit newUser = new UserAudit();

        MessageDto messageDto = new MessageDto(true, "gold", 123, "Hello World", newUser.getUserId());

        messagingTemplate.convertAndSend("/topic/messages", messageDto);

        return ResponseEntity.ok("Message sent to all users");
    }
}

目标项目pom.xml片段

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.consumer</groupId>
    <artifactId>consumersocket</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>consumersocket</name>
    <description>consumersocket</description>
    <properties>
        <java.version>17</java.version>
        <maven.compiler.source>20</maven.compiler.source>
        <maven.compiler.target>20</maven.compiler.target>
    </properties>
</project>

内容的提问来源于stack exchange,提问作者PoToM

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 16:23:31