springBoot打包出错 maven-surefire-plugin:2.18.1

springboot项目打包出错 Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1

failed to execute goal org.apache.maven.plugins:maven-surefire2.18.1

报这个错是因为单元测试不通过

解决方法:

1.去除单元测试的代码

2.执行命令 跳过测试包 mvn clean package -Dmaven.test.skip=true

3.使用idea打包时 勾选闪电图标

还有其他方式,在pom文件中加plugin设置也可以  任何一种都可 ,立刻见效,打包顺畅无阻

### 常见问题及解决方案 #### 1. 无法生成类路径及依赖信息问题 当出现 `Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project ...: Unable to generate classpath: org.apache.maven.artifact.resolver.ArtifactResolutionException: Unable to get dependency information for ...` 错误,如 `Failed to retrieve POM for org.apache.maven.surefire:surefire-junit-platform:jar:2.22.2: Could not transfer artifact org.apache.maven.surefire:surefire-junit-platform:pom:2.22.2 from/to central (https://repo.maven.apache.org/maven2): Remote host closed connection during handshake` ,这通常是网络问题导致无法从 Maven 中央仓库下载依赖。可以尝试以下方法: - 检查网络连接,确保网络稳定。 - 更换 Maven 仓库地址,在 `settings.xml` 中配置国内的镜像仓库,如阿里云镜像: ```xml <mirrors> <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url> </mirror> </mirrors> ``` #### 2. 测试失败问题 若出现 `maven-surefire-plugin:2.22.2:test (default-test) on project ...: There are test failures.` ,可以采用以下解决方案: - 跳过测试打包。在 `pom.xml` 中加入以下配置: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build> ``` 此方法适用于测试代码暂时不影响项目打包部署的情况[^2][^3]。 - 检查 JDK 版本。将 JDK 更换为父项目中配置的版本,同时检查其他地方 JDK 的配置是否一致,刷新 Maven 后,在父项目上编译所有服务[^4]。 ### 其他使用方法及注意事项 `maven-surefire-plugin` 在 `test` 阶段主要用于执行项目中的单元测试和集成测试。默认情况下,它会执行 `src/test/java` 目录下符合特定命名规则(如 `*Test.java`)的测试类。可以通过配置 `includes` 和 `excludes` 来指定要执行或排除的测试类。例如: ```xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> <configuration> <includes> <include>**/*IntegrationTest.java</include> </includes> <excludes> <exclude>**/*UnitTest.java</exclude> </excludes> </configuration> </plugin> </plugins> </build> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值