在多模块 Maven 项目的 Maven 测试构建过程中忽略模块

发布于 2025-01-05 09:52:11 字数 352 浏览 1 评论 0原文

是否可以在多模块 Maven 项目中运行 Maven 测试构建(mvn clean test)并跳过/忽略特定模块的测试?就像 -Dmaven.test.skip=true 但对于特定模块而不是所有模块?我不想更改 Surefire 以包含我想跳过测试的模块的 true 。我想知道这是否可以从命令行完成。我需要这个,因为在我的项目中,我有很多模块,并且特定的一两个模块需要很长时间才能执行测试,所以当我只想测试几个模块时,我想跳过这些我没有测试过的模块的时间进行了任何更改。

Is it possible to run a maven test build (mvn clean test) in a multi module maven project and to skip/ignore a particular module's test? like -Dmaven.test.skip=true but for a particular module and not all the modules? I dont want to change the surefire <configuration> to include <skipTests>true</skipTests> for the module which I want to skip for tests. I wanted to know if this can be done from command line. I need this because in my project I've many modules and particular one or two takes really long to execute test, so when I want to test only couple of modules I'd like to skip these time taking modules to which I've not made any changes.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

潦草背影 2025-01-12 09:52:11

更改 Surefire 插件的配置对您来说真的有问题吗?因为你只能在你的模块中更改它一次......

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

并将skipTests标签的真/假值委托给maven属性,由专用配置文件激活:

<properties>
    <skip.foo.module.tests>false</skip.foo.module.tests>
</properties>

<profiles>
    <profile>
        <id>SKIP_FOO_MODULE_TESTS</id>
        <properties>
            <skip.foo.module.tests>true</skip.foo.module.tests>
        </properties>
    </profile>
</profiles>

这样你就可以使用以下命令停用Foo模块中的测试 :命令行:

mvn clean test -P SKIP_FOO_MODULE_TESTS

Is is really a problem for you to change the configuration of the surefire plugin ? Because you could change it one time only in your module ...

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

... and delegate the true/false value of the skipTests tag to a maven property, activated by a dedicated profile :

<properties>
    <skip.foo.module.tests>false</skip.foo.module.tests>
</properties>

<profiles>
    <profile>
        <id>SKIP_FOO_MODULE_TESTS</id>
        <properties>
            <skip.foo.module.tests>true</skip.foo.module.tests>
        </properties>
    </profile>
</profiles>

So that you could deactivate the tests in Foo module with the command line :

mvn clean test -P SKIP_FOO_MODULE_TESTS

雾里花 2025-01-12 09:52:11

您可以使用配置文件来完成此操作,该配置文件执行了要跳过的 Surefire 配置。这将允许您在大部分时间保持测试运行,但是当您有时想跳过其中一个模块的测试时,您可以调用该配置文件。然后,您可以使用跳过测试排除所有测试,也可以使用排除选项仅排除一两个长时间执行的测试。

You could accomplish that with a profile that did the configuration of surefire to skip. That'd allow you to keep the test running most of the time, but when you wanted to skip the tests for one of the modules sometime, you could invoke that profile. You can then exclude all tests using skip tests or you could use the excludes option to only exclude the one or two tests that are long executing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文