问题:执行 mvn package 或 mvn install 报错:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project app: There are test failures.
[ERROR]
[ERROR] Please refer to E:\work\lhtex-api\target\surefire-reports for the individual test results.
解决方案:
方法1 命令后加上如下代码
mvn clean package -DskipTests
或
mvn clean package -Dmaven.test.skip=true
方法2 pom文件properties标签加上如下代码
<!-- 相当于 -DskipTests,不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下。-->
<!--<skipTests>true</skipTests>-->
<!-- 相当于 -Dmaven.test.skip=true,不执行测试用例,也不编译测试用例类。-->
<maven.test.skip>true</maven.test.skip>
方法3 pom文件加上如下代码
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
以上可参照官网:http://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-tests.html
方法4 IDEA设置
![](https://img-blog.csdnimg.cn/20190705113954671.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjAzMjE5OQ==,size_16,color_FFFFFF,t_70)
记一下package 与 install 区别
mvn clean package依次执行:7个阶段
clean、resources、compile、testResources、testCompile、test、war(jar)
mvn clean install依次执行:8个阶段
clean、resources、compile、testResources、testCompile、test、war(jar)、install
maven-war-plugin将工程打包成war
maven-install-plugin会将打好的war包放入本地开发环境的maven版本库