事故现场:执行 mvn clean install 报错:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.20.1:test (default-test) on project xxx-service: There are test failures.
原因:
surefire 是一个测试插件,默认情况下,surefire 会执行文件名以 Test 开头或结尾的测试用例,或者是以 TestCase 结尾的测试用例。
pom 配置如下,猜测version 与 jvm 环境(jdk1.8)不match
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
解决办法参考:
1.更换 version
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
2. 跳过 test
2.1 执行 mvn clean install -Dmaven.test.skip=true
2.2 调整 pom 文件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
2.3 只跳过执行失败的 test
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>