简体   繁体   English

动态包含和排除maven-surefire-plugin

[英]Dynamically Include and Exclude for maven-surefire-plugin

Could you please advise me on whether or not I can dynamically change Include and Exclude for the Maven Surfire Plugin? 您能否建议我是否可以动态更改Maven Surfire插件的“ Include和“ Exclude ”?

For example: 例如:

<build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.18.1</version>
                        <configuration>
                            <includes>
                                <include>**/${param}Spec*.*</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>

I would like to have $param passed from the command line when we perform the Maven test command. 当我们执行Maven测试命令时,我希望从命令行传递$param

Please give advice if you have a solution. 如果您有解决方案,请提供建议。 I have tried argline and systemProperties 我曾尝试arglinesystemProperties

Thanks! 谢谢!

I don't think there is a way to pass dynamic parameter, but you can use below trick if you have limited combinations of exclusions/inclusions. 我认为没有传递动态参数的方法,但是如果排除项/包含项的组合有限,则可以使用以下技巧。 Trick is using profiles with different combinations like combo1, combo2 etc. Then you can run maven build with specific profile & only those include/exclude will work. Trick正在使用具有不同组合(例如combo1,combo2等)的配置文件。然后,您可以使用特定配置文件运行maven build,只有那些包含/排除项才能起作用。

Command = mvn clean package -P combo1 命令= mvn clean package -P combo1

pom.xml 的pom.xml

<profiles>
    <profile>
        <id>combo1</id>
        <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.18.1</version>
                        <configuration>
                            <includes>
                                <include>**/Combo1Spec*.*</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
    </profile>

    <profile>
        <id>combo2</id>
        <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.18.1</version>
                        <configuration>
                            <includes>
                                <include>**/Combo2Spec*.*</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
    </profile>
</profiles>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM