How can I prevent tests from being run when using exec-maven-plugin

痴心易碎 提交于 2020-05-26 00:18:26

问题


I am running JavaScript unit tests in a maven project using exec-maven-plugin

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <id>run-karma</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>${node.bin.folder}/node</executable>
                <workingDirectory>${project.basedir}</workingDirectory>
                <arguments>
                    <argument>node_modules/karma/bin/karma</argument>
                    <argument>start</argument>
                    <argument>--single-run</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

I was under the assumption that if I passed -DskipTests, the entire test phase would be skipped but that's not the case, the skipTests flag is only honored when using "Surefire, Failsafe and the Compiler Plugin"

Question: How can I make that execution depend on the skipTests flag?


回答1:


You can use the skip option of the exec-maven-plugin as following:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.5.0</version>
            <executions>
                <execution>
                    <id>run-karma</id>
                    <phase>test</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>cmd</executable>
                        <arguments>
                            <argument>/C</argument>
                            <argument>echo</argument>
                            <argument>hello</argument>
                        </arguments>
                        <skip>${skipTests}</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Note the usage of ${skipTests} as part of its value. Also note I used a newer version, 1.5.0, recommended.

Running:

mvn clean test -DskipTests

The output would contain:

[INFO] Tests are skipped.   
[INFO]   
[INFO] --- exec-maven-plugin:1.5.0:exec (run-karma) @ sample-project ---   
[INFO] skipping execute as per configuration   
[INFO] ------------------------------------------------------------------------   
[INFO] BUILD SUCCESS   

While executing:

mvn clean test

The output would be

Tests run: 8, Failures: 0, Errors: 0, Skipped: 0   

[INFO]   
[INFO] --- exec-maven-plugin:1.5.0:exec (run-karma) @ sample-project ---   
hello   
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS   


来源:https://stackoverflow.com/questions/37858749/how-can-i-prevent-tests-from-being-run-when-using-exec-maven-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!