我正设法把我的项目打包。但是,在执行打包之前,它会自动运行测试。测试在数据库中插入一些内容。这不是我想要的,我需要避免在打包应用程序时运行测试。有人知道如何运行没有测试的包吗?


当前回答

对于不感染maven测试的maven包:

<properties>
    <maven.test.failure.ignore>true</maven.test.failure.ignore>
</properties>

其他回答

mvn package -Dmaven.test.skip=true

运行maven

mvn package -Dmaven.test.skip

回答一个老生常谈的问题。如果你想避免一直传递命令行参数,你可以在pom.xml中添加这个:

  <properties>
    <skipTests>true</skipTests>
  </properties>

如果你在Windows Powershell中尝试这个,你会得到这个错误:

[ERROR] Unknown lifecycle phase ".test.skip=true". You must specify a valid lifecycle phase or a goal in the format...

这样做的原因是,在Powershell中“-”有特殊的含义,它会导致maven的问题。

解决方案是在它前面加上一个反撇号('),就像这样..

mvn `-Dmaven.test.skip=true install 

参考:http://kuniganotas.wordpress.com/2011/08/12/invalid-task-test-skiptrue-you-must-specify-a-valid-lifecycle-phase/

You are, obviously, doing it the wrong way. Testing is an important part of pre-packaging. You shouldn't ignore or skip it, but rather do it the right way. Try changing the database to which it inserts the data(like test_db). It may take a while to set it up. And to make sure this database can be used forever, you should delete all the data by the end of tests. JUnit4 has annotations which make it easy for you. Use @Before, @After @Test annotations for the right methods. You need to spend sometime on it, but it will be worth it!