I am new to Maven. I am trying to package my project. But, it automatically runs the tests. 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?
我是Maven的新手。我正试着包装我的项目。但是,它会自动运行测试。测试在数据库中插入一些内容。这不是我想要的,我需要在打包应用程序时避免运行测试。有人知道如何运行包而不进行测试吗?
15 个解决方案
#1
385
Run maven with -Dmaven.test.skip=true
运行maven -Dmaven.test.skip = true
#2
123
Just provide the command mentioned below which will ignore executing the test cases,
只需提供下面提到的命令,它将忽略执行测试用例,
mvn package -DskipTests
#3
42
you can add this plugin configuration to your pom if you do not want to set command line arg:
如果您不想设置命令行arg,可以将这个插件配置添加到pom中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
#4
30
Note that -Dmaven.test.skip prevents Maven building the test-jar artifact.
注意,-Dmaven.test。skip阻止Maven构建测试jar工件。
If you'd like to skip tests but create artifacts as per a normal build use:
如果您想跳过测试,但是按照正常的构建使用创建工件:
-Dmaven.test.skip.exec
#5
21
If you are trying this in Windows Powershell, you will get this error:
如果你在Windows Powershell中尝试这个,你会得到以下错误:
[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.
原因是,在Powershell中,“-”有特殊的含义,它正在引起maven的问题。
The solution is to prepend it with a backtick (`), like so..
解决方案是用一个backtick(')来prepend it,就像这样。
mvn `-Dmaven.test.skip=true install
参考:http://kuniganotas.wordpress.com/2011/08/12/invalid-task-test-skiptrue-you-must-specify-a-valid-lifecycle-phase/
#6
19
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
is also a way to add in pom file
也是添加pom文件的一种方式吗
#7
17
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:
你可以通过考试。跳过标志作为JVM参数,在包阶段(以及默认生命周期中的前一个阶段)运行时跳过运行测试:
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.
还可以将skipTests标志单独传递给mvn可执行文件。如果您想在POM中包含这些信息,您可以创建一个新的概要文件,在那里您可以配置maven-surefire插件来跳过测试。
#8
12
You only have to provide
你只需要提供
-Dmaven.test.skip
No longer need the '=true' there.
这里不再需要'=true'了。
#9
9
Answering an old and accepted question here. You can add this in your pom.xml if you want to avoid passing command line argument all the time:
回答一个老问题。您可以在您的pom中添加这个。如果您希望避免始终传递命令行参数,请使用xml:
<properties>
<skipTests>true</skipTests>
</properties>
#10
4
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]。如果你需要关闭测试,你做错了什么。换句话说,你试图解决错误的问题。找出你真正的问题,然后问这个问题。它听起来像是与数据库相关的。
[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.
当您需要快速地为本地的开发使用生成工件时,您可能会跳过测试,但是一般来说,创建工件应该始终遵循一个成功的测试运行。
#11
1
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!
很明显,你做错了。测试是预包装的重要组成部分。你不应该忽视或跳过它,而应该用正确的方式去做。尝试更改它插入数据的数据库(如test_db)。可能需要一段时间才能建立起来。为了确保这个数据库可以永远使用,您应该在测试结束时删除所有数据。JUnit4有注释,使您更容易使用。对正确的方法使用@Before、@After @Test注释。你需要花点时间在它上面,但它是值得的!
#12
1
mvn clean install -Dmaven.test.skip=true
mvn清洁安装-Dmaven.test.skip = true
worked for me since the -Dskip
did not work anymore.
自从-Dskip不再工作以来,我一直在为我工作。
#13
0
mvn package -Dmaven.test.skip=true
#14
0
The best and the easiest way to do it, in IntelliJ Idea in the window “Maven Project”, and just don’t click on the test button. I hope, I helped you. Have a good day :)
最好、最简单的方法是,在窗口“Maven项目”中的IntelliJ Idea中,不要单击test按钮。我希望我帮了你。祝你过得愉快
#15
0
In Intellij, go to View -> Tool Windows -> choose Maven Projects. On the Lifecyle dropdown, right-click on package -> choose Create 'your-project [package]'...
在Intellij中,转到View ->工具窗口->选择Maven项目。在生命周期下拉菜单上,右键单击package ->选择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.
输入这个值:package -Dmaven.test。跳过= true - f砰的一声。命令行字段中的xml。单击Apply和一个运行配置下拉菜单应该与您创建的定制maven命令一起出现。
#1
385
Run maven with -Dmaven.test.skip=true
运行maven -Dmaven.test.skip = true
#2
123
Just provide the command mentioned below which will ignore executing the test cases,
只需提供下面提到的命令,它将忽略执行测试用例,
mvn package -DskipTests
#3
42
you can add this plugin configuration to your pom if you do not want to set command line arg:
如果您不想设置命令行arg,可以将这个插件配置添加到pom中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
#4
30
Note that -Dmaven.test.skip prevents Maven building the test-jar artifact.
注意,-Dmaven.test。skip阻止Maven构建测试jar工件。
If you'd like to skip tests but create artifacts as per a normal build use:
如果您想跳过测试,但是按照正常的构建使用创建工件:
-Dmaven.test.skip.exec
#5
21
If you are trying this in Windows Powershell, you will get this error:
如果你在Windows Powershell中尝试这个,你会得到以下错误:
[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.
原因是,在Powershell中,“-”有特殊的含义,它正在引起maven的问题。
The solution is to prepend it with a backtick (`), like so..
解决方案是用一个backtick(')来prepend it,就像这样。
mvn `-Dmaven.test.skip=true install
参考:http://kuniganotas.wordpress.com/2011/08/12/invalid-task-test-skiptrue-you-must-specify-a-valid-lifecycle-phase/
#6
19
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
is also a way to add in pom file
也是添加pom文件的一种方式吗
#7
17
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:
你可以通过考试。跳过标志作为JVM参数,在包阶段(以及默认生命周期中的前一个阶段)运行时跳过运行测试:
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.
还可以将skipTests标志单独传递给mvn可执行文件。如果您想在POM中包含这些信息,您可以创建一个新的概要文件,在那里您可以配置maven-surefire插件来跳过测试。
#8
12
You only have to provide
你只需要提供
-Dmaven.test.skip
No longer need the '=true' there.
这里不再需要'=true'了。
#9
9
Answering an old and accepted question here. You can add this in your pom.xml if you want to avoid passing command line argument all the time:
回答一个老问题。您可以在您的pom中添加这个。如果您希望避免始终传递命令行参数,请使用xml:
<properties>
<skipTests>true</skipTests>
</properties>
#10
4
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]。如果你需要关闭测试,你做错了什么。换句话说,你试图解决错误的问题。找出你真正的问题,然后问这个问题。它听起来像是与数据库相关的。
[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.
当您需要快速地为本地的开发使用生成工件时,您可能会跳过测试,但是一般来说,创建工件应该始终遵循一个成功的测试运行。
#11
1
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!
很明显,你做错了。测试是预包装的重要组成部分。你不应该忽视或跳过它,而应该用正确的方式去做。尝试更改它插入数据的数据库(如test_db)。可能需要一段时间才能建立起来。为了确保这个数据库可以永远使用,您应该在测试结束时删除所有数据。JUnit4有注释,使您更容易使用。对正确的方法使用@Before、@After @Test注释。你需要花点时间在它上面,但它是值得的!
#12
1
mvn clean install -Dmaven.test.skip=true
mvn清洁安装-Dmaven.test.skip = true
worked for me since the -Dskip
did not work anymore.
自从-Dskip不再工作以来,我一直在为我工作。
#13
0
mvn package -Dmaven.test.skip=true
#14
0
The best and the easiest way to do it, in IntelliJ Idea in the window “Maven Project”, and just don’t click on the test button. I hope, I helped you. Have a good day :)
最好、最简单的方法是,在窗口“Maven项目”中的IntelliJ Idea中,不要单击test按钮。我希望我帮了你。祝你过得愉快
#15
0
In Intellij, go to View -> Tool Windows -> choose Maven Projects. On the Lifecyle dropdown, right-click on package -> choose Create 'your-project [package]'...
在Intellij中,转到View ->工具窗口->选择Maven项目。在生命周期下拉菜单上,右键单击package ->选择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.
输入这个值:package -Dmaven.test。跳过= true - f砰的一声。命令行字段中的xml。单击Apply和一个运行配置下拉菜单应该与您创建的定制maven命令一起出现。