Spring Boot项目Maven构建失败:无法解析兄弟模块依赖问题求助

需求
我需要将兄弟模块引入到名为AccountManagementSystem的Spring Boot项目中。
我的.m2目录下没有setting.xml文件。
已尝试的解决方法
- 删除
.m2目录,问题未解决 - 执行
mvn clean install -U命令,问题仍未解决
首次报错信息
[INFO] Scanning for projects... [INFO] [INFO] --------< com.AccountManagementSystem:AccountManagementSystem >--------- [INFO] Building AccountManagementSystem 0.0.1 [INFO] --------------------------------[ war ]--------------------------------- [INFO] Downloading from : https://repo.maven.apache.org/maven2/com/EncapsulationSystem/EncapsulationSystem/1.0/EncapsulationSystem-1.0.pom [WARNING] The POM for com.EncapsulationSystem:EncapsulationSystem:jar:1.0 is missing, no dependency information available [INFO] Downloading from : https://repo.maven.apache.org/maven2/jc/adwords-encapsulation/1.0/adwords-encapsulation-1.0.pom [WARNING] The POM for jc:adwords-encapsulation:jar:1.0 is missing, no dependency information available [INFO] Downloading from : https://repo.maven.apache.org/maven2/com/PermissionSystemApiTool/PermissionSystemApiTool/0.0.1/PermissionSystemApiTool-0.0.1.pom [WARNING] The POM for com.PermissionSystemApiTool:PermissionSystemApiTool:jar:0.0.1 is missing, no dependency information available [INFO] Downloading from : https://repo.maven.apache.org/maven2/com/EncapsulationSystem/EncapsulationSystem/1.0/EncapsulationSystem-1.0.jar [INFO] Downloading from : https://repo.maven.apache.org/maven2/com/PermissionSystemApiTool/PermissionSystemApiTool/0.0.1/PermissionSystemApiTool-0.0.1.jar [INFO] Downloading from : https://repo.maven.apache.org/maven2/jc/adwords-encapsulation/1.0/adwords-encapsulation-1.0.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.800 s [INFO] Finished at: 2021-11-15T16:47:06+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project AccountManagementSystem: Could not resolve dependencies for project com.AccountManagementSystem:AccountManagementSystem:war:0.0.1: The following artifacts could not be resolved: com.EncapsulationSystem:EncapsulationSystem:jar:1.0, jc:adwords-encapsulation:jar:1.0, com.PermissionSystemApiTool:PermissionSystemApiTool:jar:0.0.1: Could not find artifact com.EncapsulationSystem:EncapsulationSystem:jar:1.0 in central (https://repo.maven.apache.org/maven2) -> [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
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> <packaging>war</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.4</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>com.AccountManagementSystem</groupId> <artifactId>AccountManagementSystem</artifactId> <version>0.0.1</version> <name>AccountManagementSystem</name> <description>Account Management System</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>com.EncapsulationSystem</groupId> <artifactId>EncapsulationSystem</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>jc</groupId> <artifactId>adwords-encapsulation</artifactId> <version>1.0</version> <exclusions> <exclusion> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <exclusions> <exclusion> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-jdbc</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j</artifactId> <version>1.2.2.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>com.google.oauth-client</groupId> <artifactId>google-oauth-client-jetty</artifactId> <version>1.32.1</version> </dependency> <dependency> <groupId>javax.activation</groupId> <artifactId>activation</artifactId> <version>1.1</version> </dependency> <dependency> <groupId>com.PermissionSystemApiTool</groupId> <artifactId>PermissionSystemApiTool</artifactId> <version>0.0.1</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.amven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
后续执行报错
执行mvn clean install命令时,仍收到如下报错:
[INFO] Scanning for projects... [INFO] [INFO] --------< com.AccountManagementSystem:AccountManagementSystem >--------- [INFO] Building AccountManagementSystem 0.0.1 [INFO] --------------------------------[ war ]--------------------------------- [WARNING] The POM for com.EncapsulationSystem:EncapsulationSystem:jar:1.0 is missing, no dependency information available [WARNING] The POM for jc:adwords-encapsulation:jar:1.0 is missing, no dependency information available [WARNING] The POM for com.PermissionSystemApiTool:PermissionSystemApiTool:jar:0.0.1 is missing, no dependency information available [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.912 s [INFO] Finished at: 2021-11-15T16:58:46+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project AccountManagementSystem: Could not resolve dependencies for project com.AccountManagementSystem:AccountManagementSystem:war:0.0.1: The following artifacts could not be resolved: com.EncapsulationSystem:EncapsulationSystem:jar:1.0, jc:adwords-encapsulation:jar:1.0, com.PermissionSystemApiTool:PermissionSystemApiTool:jar:0.0.1: com.EncapsulationSystem:EncapsulationSystem:jar:1.0 was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced -> [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
问题解决步骤
报错核心原因是你依赖的三个兄弟模块没有被安装到本地Maven仓库,Maven默认去公共中央仓库检索,自然找不到私有模块。按以下步骤操作即可:
- 分别进入EncapsulationSystem、adwords-encapsulation、PermissionSystemApiTool三个模块的根目录(即各自pom.xml所在目录),每个目录下都执行一遍
mvn clean install,执行成功后三个模块的jar包和配置信息就会被写入本地.m2仓库。 - 修正当前主pom的笔误:maven-surefire-plugin的groupId应为
org.apache.maven.plugins,你写的org.apache.amven.plugins拼写错误,也会引发构建异常。 - 回到AccountManagementSystem项目根目录,执行
mvn clean install -U即可完成构建。
如果四个模块属于同一个父聚合项目,只需要在父pom的<modules>标签中把所有子模块都列全,直接在父项目根目录执行mvn clean install,Maven会自动按依赖顺序编译安装所有模块,无需单独处理每个子模块。
内容的提问来源于stack exchange,提问作者AI中心陳寧寬
相关产品推荐
相关产品推荐

