如何让maven cobertura和surefire插件协同工作?

如何让maven cobertura和surefire插件协同工作?,maven,configuration,cobertura,maven-surefire-plugin,Maven,Configuration,Cobertura,Maven Surefire Plugin,我将surefire和cobertura插件放在我的pom.xml中,但我无法将它们配置为正常工作。或者cobertura没有运行,或者测试执行了两次 那么,我如何配置插件,让它们一起运行并且只运行一次呢 如果以这种方式配置,则cobertura不会运行: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifact

我将surefire和cobertura插件放在我的
pom.xml
中,但我无法将它们配置为正常工作。或者cobertura没有运行,或者测试执行了两次

那么,我如何配置插件,让它们一起运行并且只运行一次呢

如果以这种方式配置,则cobertura不会运行:

<plugin>
<groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
    <version>2.12</version>
</plugin>

org.codehaus.mojo
cobertura maven插件
2.5.1
org.apache.maven.plugins
maven surefire插件
2.12
如果以这种方式进行配置,测试将执行两次:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.5.1</version>
    <executions>
        <execution>
            <phase>test</phase>
            <goals>
                <goal>cobertura</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12</version>
</plugin>

org.codehaus.mojo
cobertura maven插件
2.5.1
测试
科贝图拉
org.apache.maven.plugins
maven surefire插件
2.12

测试将运行两次-就是这样。参见Samuel的评论

这就是我如何让它在cobertura打开和surefire关闭的情况下用于测试的。 将其添加到pom中,或者为-DuseSystemClassLoader=false添加mvn选项

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <useSystemClassLoader>false</useSystemClassLoader>
                <testFailureIgnore>true</testFailureIgnore>
            </configuration>
        </plugin>

org.apache.maven.plugins
maven surefire插件
2.19.1
假的
真的

maven的目标是什么?另一种选择是使用声纳。运行这两个工具,无需更改POM文件(插件由属性驱动,您可以在设置文件中设置属性)。我已在主题中添加了POM.xml的一部分。您可以查看以下内容: