0

我正在使用 cobertura 和 Maven 来生成代码覆盖率报告。当测试用例没有覆盖足够的代码时,我们希望能够使构建失败。基于 maven-cobertura-plugin 的"check" 网页,我配置了我的 pom 文件,如下所示:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <check>
                    <branchRate>85</branchRate>
                    <lineRate>85</lineRate>
                    <haltOnFailure>true</haltOnFailure>
                    <totalBranchRate>85</totalBranchRate>
                    <totalLineRate>85</totalLineRate>
                    <packageLineRate>85</packageLineRate>
                    <packageBranchRate>85</packageBranchRate>
                </check>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>clean</goal>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.6</version>
        </plugin>
    </plugins>
</reporting>

当我执行 maven 时,我收到此错误:

目标 org.codehaus.mojo:cobertura-maven-plugin:2.6:check 的参数“检查”丢失或无效

我尝试在调试模式下运行,我在输出中看到了这一点check

[信息] --- cobertura-maven-plugin:2.6:check (default-cli) @ MyApplication ---
[调试] 配置 mojo org.codehaus.mojo:cobertura-maven-plugin:2.6:check from plugin realm ClassRealm[plugin>org.codehaus.mojo:cobertura-maven-plugin:2.6, parent: sun.misc.Launcher$AppClassLoader @9b6d0342]
[调试] 使用基本配置器配置 mojo 'org.codehaus.mojo:cobertura-maven-plugin:2.6:check' -->
[调试] (f) 数据文件 = G:\dev\MyApplication\target\cobertura\cobertura.ser
[调试] (f) forceMojoExecution = false
[调试] (f) maxmem = 64m
[调试] (f) mojoExecution = org.codehaus.mojo:cobertura-maven-plugin:2.6:check {execution: default-cli}
[调试] (f) pluginClasspathList = [org.codehaus.mojo:cobertura-maven-plugin:maven-plugin:2.6:, net.sourceforge.cobertura:cobertura:jar:2.0.3:compile, org.ow2.asm: asm:jar:4.1:compile, org.ow2.asm:asm-tree:jar:4.1:compile, org.ow2.asm:asm-commons:jar:4.1:compile, org.ow2.asm:asm-util: jar:4.1:compile, org.ow2.asm:asm-analysis:jar:4.1:compile, oro:oro:jar:2.0.8:compile, jaxen:jaxen:jar:1.1-beta-8:compile, dom4j: dom4j:jar:1.6.1:compile, jdom:jdom:jar:1.0:compile, xerces:xmlParserAPIs:jar:2.6.2:compile, xerces:xercesImpl:jar:2.6.2:compile, xom:xom:jar: 1.0b3:compile, com.ibm.icu:icu4j:jar:2.6.1:compile, xalan:xalan:jar:2.6.0:compile, org.ccil.cowan.tagsoup:tagsoup:jar:0.9.7:compile , org.apache.ant:ant:jar:1.8.3:compile, org.apache.ant:ant-launcher:jar:1.8.3:compile, org.mortbay.jetty:servlet-api-2.5:jar:6.1 .14:编译,org.mortbay.jetty:jetty:jar:6.1。14:编译,org.mortbay.jetty:jetty-util:jar:6.1.14:编译,com.sun:tools:jar:0:system,log4j:log4j:jar:1.2.9:编译,net.sourceforge。 cobertura:cobertura-runtime:pom:2.0.3:compile, urbanophile:java-getopt:jar:1.0.9:compile, commons-cli:commons-cli:jar:1.0:compile, org.codehaus.plexus:plexus- interactivity-api:jar:1.0-alpha-4:compile, org.apache.maven.reporting:maven-reporting-api:jar:2.0.8:compile, org.apache.maven.doxia:doxia-sink-api: jar:1.0-alpha-9:compile, org.apache.maven.reporting:maven-reporting-impl:jar:2.0.4.2:compile, commons-validator:commons-validator:jar:1.2.0:compile, commons- beanutils:commons-beanutils:jar:1.7.0:compile, commons-digester:commons-digester:jar:1.6:compile, commons-logging:commons-logging:jar:1.0.4:compile, xml-apis:xml- apis:jar:1.0.b2:compile, org.apache.maven.doxia:doxia-core:jar:1.0:compile, org.apache.maven.doxia:doxia-site-renderer:jar:1.0:compile, org.codehaus.plexus:plexus-i18n:jar:1.0-beta-7:compile, org.codehaus.plexus:plexus-velocity:jar:1.1.7:compile, org.apache.velocity:velocity:jar:1.5:compile, org.apache.maven.doxia:doxia-decoration-model:jar:1.0:compile, commons-collections:commons-collections:jar:3.2:compile, org. apache.maven.doxia:doxia-module-apt:jar:1.0:compile, org.apache.maven.doxia:doxia-module-fml:jar:1.0:compile, org.apache.maven.doxia:doxia-module- xdoc:jar:1.0:compile, org.apache.maven.doxia:doxia-module-xhtml:jar:1.0:compile, commons-lang:commons-lang:jar:2.4:compile, org.codehaus.plexus:plexus- utils:jar:2.0.2:compile, org.apache.maven.shared:maven-invoker:jar:2.0.11:compile]velocity:velocity:jar:1.5:compile, org.apache.maven.doxia:doxia-decoration-model:jar:1.0:compile, commons-collections:commons-collections:jar:3.2:compile, org.apache.maven。 doxia:doxia-module-apt:jar:1.0:compile, org.apache.maven.doxia:doxia-module-fml:jar:1.0:compile, org.apache.maven.doxia:doxia-module-xdoc:jar: 1.0:编译,org.apache.maven.doxia:doxia-module-xhtml:jar:1.0:编译,commons-lang:commons-lang:jar:2.4:编译,org.codehaus.plexus:plexus-utils:jar: 2.0.2:编译,org.apache.maven.shared:maven-invoker:jar:2.0.11:compile]velocity:velocity:jar:1.5:compile, org.apache.maven.doxia:doxia-decoration-model:jar:1.0:compile, commons-collections:commons-collections:jar:3.2:compile, org.apache.maven。 doxia:doxia-module-apt:jar:1.0:compile, org.apache.maven.doxia:doxia-module-fml:jar:1.0:compile, org.apache.maven.doxia:doxia-module-xdoc:jar: 1.0:编译,org.apache.maven.doxia:doxia-module-xhtml:jar:1.0:编译,commons-lang:commons-lang:jar:2.4:编译,org.codehaus.plexus:plexus-utils:jar: 2.0.2:编译,org.apache.maven.shared:maven-invoker:jar:2.0.11:compile]org.apache.maven.doxia:doxia-module-xhtml:jar:1.0:compile, commons-lang:commons-lang:jar:2.4:compile, org.codehaus.plexus:plexus-utils:jar:2.0.2:编译,org.apache.maven.shared:maven-invoker:jar:2.0.11:compile]org.apache.maven.doxia:doxia-module-xhtml:jar:1.0:compile, commons-lang:commons-lang:jar:2.4:compile, org.codehaus.plexus:plexus-utils:jar:2.0.2:编译,org.apache.maven.shared:maven-invoker:jar:2.0.11:compile]
[调试] (f) 项目 = MavenProject: com.mycompany:MyApplication1.0.0 @G:\dev\MyApplication\pom.xml
[调试] (f) 安静 = 假
[调试] (f) 跳过 = 假
[DEBUG] -- 结束配置 --

我没有看到任何明显错误的地方,所以我不确定为什么我不能运行check

我正在从 RAD 8.5 运行嵌入式版本的 Maven,使用具有此目标的运行配置:

清洁 cobertura:检查

如果我将构建运行为

清洁 cobertura:cobertura

检查过程没有运行并且构建成功,即使我知道我的覆盖率低于 85%。

有谁知道有什么问题cobertura:check以及我怎样才能让它工作?

4

2 回答 2

0

似乎做我想做的事情的正确方法是用目标调用 Maven clean verify site:.

于 2014-07-18T17:27:59.003 回答
0

在插件标签内的 pom.xml 中使用下面

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <formats>
                        <format>html</format>
                        <format>xml</format>
                    </formats>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>cobertura</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

并在 pom.xml 的项目标签中使用下面。

<reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.6</version>
            </plugin>
        </plugins>
    </reporting>

这对我有用

于 2015-05-26T12:11:24.730 回答