Java Maven -DskipTests 被忽略

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19838734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 20:36:28  来源:igfitidea点击:

Maven -DskipTests ignored

javamavenjunitmaven-surefire-plugin

提问by NeplatnyUdaj

I'm building a Maven project with following SureFireconfiguration:

我正在使用以下SureFire配置构建一个 Maven 项目:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${version.maven-surefire-plugin}</version>
    <configuration>
        <includes>
            <include>**/*Test.java</include>
        </includes>
    </configuration>
</plugin>

Problem is, that when I build it with mvn clean install -DskipTests=true, the tests are still being executed. What could be the problem?

问题是,当我用 构建它时mvn clean install -DskipTests=true,测试仍在执行。可能是什么问题呢?

I tried both -DskipTests(which is from the Maven website) and -DskipTests=true, which is added by IntelliJ Idea when I check "skip tests" checkbox.

我尝试了两者-DskipTests(来自Maven 网站)和-DskipTests=true,这是在我选中“跳过测试”复选框时由 IntelliJ Idea 添加的。

I don't use any Maven settings.xml.

我不使用任何 Maven settings.xml

  • Maven version: 2.2.1
  • Surefire plugin: 2.3
  • Maven 版本:2.2.1
  • Surefire 插件:2.3

EDITIf I comment out the SureFire plugin configuration, the parameter behaves as I expect to. What could be the problem with the configuration above?

编辑如果我注释掉 SureFire 插件配置,则该参数的行为与我预期的一样。上面的配置可能有什么问题?

采纳答案by Aaron Digulla

What you did should work. How to debug this further:

你所做的应该有效。如何进一步调试:

  1. Run mvn help:effective-pomto see the whole POM that Maven will execute. Search it for test(case insensitive) to see if there is something odd.

  2. Run mvn test -Xto get debug output. This will print the options used to configure the maven-surefire-plugin. Make sure you redirect the output to a file!

    In the log, you will see

    [DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.15:test' with basic configurator -->
    

    and then, some lines below that:

    [DEBUG]   (s) runOrder = filesystem
    [DEBUG]   (s) skip = false
    [DEBUG]   (s) skipTests = false
    

    These values mean that tests aren't skipped.

  3. Are you using a recent version of the plugin? Check here. Maybe this option wasn't supported for your version.

  1. 运行mvn help:effective-pom以查看 Maven 将执行的整个 POM。搜索它test(不区分大小写)以查看是否有奇怪的地方。

  2. 运行mvn test -X以获取调试输出。这将打印用于配置maven-surefire-plugin. 确保将输出重定向到文件!

    在日志中,你会看到

    [DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.15:test' with basic configurator -->
    

    然后,下面的一些行:

    [DEBUG]   (s) runOrder = filesystem
    [DEBUG]   (s) skip = false
    [DEBUG]   (s) skipTests = false
    

    这些值意味着不会跳过测试。

  3. 您使用的是最新版本的插件吗?检查这里。也许您的版本不支持此选项。

回答by Andrei Nicusan

Try the following configuration for your surefire plugin

为您的 surefire 插件尝试以下配置

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${version.surefire.plugin}</version>
    <configuration>
        <skip>true</skip>
    </configuration>
</plugin>

回答by Hyman

Maven knows two types of parameters for skipping tests:

Maven 知道两种用于跳过测试的参数:

-Dmaven.test.skip=true 

or

或者

-DskipTests=true 

The surefire-plugin documentationonly mentions the first one, which you have not tried yet.

神火-插件文件只提到第一位的,你还没有尝试过。

回答by Raji

it is not -DskipTests=trueit is just -DskipTestsconsidering you are using surfire version 2.3

-DskipTests=true不仅仅是-DskipTests考虑到您使用的是 surfire 2.3 版

so you run it as

所以你运行它

mvn install -DskipTests

回答by Chris

I'm not sure why the correct answer hasn't been posted yet. In older versions of SureFire the flag to compile tests but not run them is -Dmaven.test.skip.exec.

我不确定为什么还没有发布正确的答案。在旧版本的 SureFire 中,编译测试但不运行它们的标志是-Dmaven.test.skip.exec.

回答by jswieca

It's old question, but maybe my case help for someone.

这是个老问题,但也许我的案例对某人有帮助。

So, -DskipTests/-DskipTests=true/-DskipITs/etc didn't work, and I didn't know why. I had <profiles>in my parent pom.xmland problem was in configuration of surefire/failsafe.

所以,-DskipTests/-DskipTests=true/-DskipITs/etc 不起作用,我不知道为什么。我<profiles>在我的父母中有pom.xml问题,问题出在surefire/failsafe的配置上。

<profiles>
        <profile>
            <id>unit-test</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>integration-test</id>
            <properties>
                <skip.unit-tests>true</skip.unit-tests>
                <skip.integration-tests>false</skip.integration-tests>
                <skip.end-to-end-tests>true</skip.end-to-end-tests>
            </properties>
        </profile>
...
</profiles>

In plugins configuration I used like below:

在我使用的插件配置中,如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven-surefire-plugin.version}</version>
    <configuration>
        <skipTests>${skip.unit-tests}</skipTests>
    </configuration>
...
</plugin>

This command didn't work:

此命令不起作用:

mvn clean install -DskipTests -DskipITs

This works:

这有效:

mvn clean install -Dskip.unit-tests=true -Dskip.integration-tests=true -Dskip.end-to-end-tests=true