I am trying to package my project. But, it automatically runs the tests previous do performing the packaging. The tests insert some content in the database. This is not what I want, I need to avoid running tests while package the application. Anybody knows how run the package with out test?
21 Answers
If you are trying this in Windows Powershell, you will get this error:
[ERROR] Unknown lifecycle phase ".test.skip=true". You must specify a valid lifecycle phase or a goal in the format...
The reason for this is, in Powershell the "-
" has special meaning and it is causing problem with maven.
The solution is to prepend it with a backtick (`), like so..
mvn `-Dmaven.test.skip=true install
You can pass the maven.test.skip
flag as a JVM argument, to skip running tests when the package phase (and the previous ones in the default lifecycle) is run:
mvn package -Dmaven.test.skip=true
You can also pass the skipTests
flag alone to the mvn executable. If you want to include this information in your POM, you can create a new profile where you can configure the maven-surefire-plugin
to skip tests.
Tests should always[1] run before package. If you need to turn off the tests, you're doing something wrong. In other words, you're trying to solve the wrong problem. Figure out what your problem really is, and ask that question. It sounds like it's database-related.
[1] You might skip tests when you need to quickly generate an artifact for local, development use, but in general, creating an artifact should always follow a successful test run.
In Intellij, go to View -> Tool Windows -> choose Maven Projects. On the Lifecyle dropdown, right-click on package -> choose Create 'your-project [package]'...
Enter this value: package -Dmaven.test.skip=true -f pom.xml
in the Command line field. Click Apply and a Run Configurations dropdown menu should appear along with your created custom maven command.
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!