问题描述
我正在使用Maven 2.2.1并使用以下命令来构建我的项目
I am using Maven 2.2.1 and to build my project I used this command
mvn clean install -Dmaven.test.skip=true
但是,该构建失败,因为它找不到其中一个工件.但是,当我使用时:
However, the build failed saying it couldn't find one of the artifact. However, when I used:
mvn clean install -DskipTests
一切正常.
到目前为止,我一直认为这两个命令是等效的.但是,此链接似乎表明-Dmaven.test.skip=true
也跳过了编译测试用例.
So far I have been thinking that these 2 commands are equivalent. However, this link seems to suggest that -Dmaven.test.skip=true
also skips compiling the test cases.
但是,这仍然没有向我解释为什么一个命令有效而另一个命令无效的原因.如果有人请向我解释,将不胜感激.
However, that still didn't explain to me why one command is working and another is not. Will be thankful if anyone please explain this to me.
推荐答案
如您所述,-Dmaven.test.skip=true
跳过了对测试的编译.更重要的是,它跳过了构建测试工件的过程.大型项目的常见做法是在同一项目的模块之间共享测试实用程序和基类.
As you noted, -Dmaven.test.skip=true
skips compiling the tests. More to the point, it skips building the test artifacts. A common practice for large projects is to have testing utilities and base classes shared among modules in the same project.
这是通过使模块需要先前构建的模块的test-jar
来完成的:
This is accomplished by having a module require a test-jar
of a previously built module:
<dependency>
<groupId>org.myproject.mygroup</groupId>
<artifactId>common</artifactId>
<version>1.0</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
如果指定了-Dmaven.test.skip=true
(或简称为-Dmaven.test.skip
),则不会构建test-jar
,并且依赖于它们的任何模块都将无法构建.
If -Dmaven.test.skip=true
(or simply -Dmaven.test.skip
) is specified, the test-jar
s aren't built, and any module that relies on them will fail its build.
相反,当您使用-DskipTests
时,Maven不会运行测试,但会编译它们并构建测试jar,使其可用于后续模块.
In contrast, when you use -DskipTests
, Maven does not run the tests, but it does compile them and build the test-jar, making it available for the subsequent modules.
这篇关于Maven跳过测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!