首页 > 解决方案 > 尽管在 pom 中排除条目,但 Maven 命令不排除任何内容

问题描述

尽管文件中的插件配置<exclude>下有条目,但哪个 maven 命令可用于执行所有测试?surefirepom.xml

例如 - 以下是来自pom.xml但我不想排除的部分TestA.java。可以使用哪个maven命令?

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <excludes>
        <exclude>**/TestA.java</exclude>
    </excludes>
 </configuration>
</plugin>

标签: mavenmaven-3maven-pluginmaven-surefire-plugin

解决方案


将配置文件添加到您的 pom.xml

<profiles>
    <profile>
        <id>all-tests</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <excludes>
                            <exclude></exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

此配置文件会覆盖 surefire 插件的排除部分。只需通过以下方式激活配置文件:

mvn clean install -Pall-tests

推荐阅读