我正在使用带有Maven的cobertura来生成代码覆盖率报告。当测试用例没有足够的代码时,我们希望能够使构建失败。基于maven-cobertura-plugin的web page for "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的参数'check':cobertura-maven-plugin:2.6:检查丢失或无效
我尝试在调试模式下运行,我在check
的输出中看到了这一点:
[INFO] --- cobertura-maven-plugin:2.6:check (default-cli) @ MyApplication --- [DEBUG] Configuring 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] [DEBUG] Configuring mojo 'org.codehaus.mojo:cobertura-maven-plugin:2.6:check' with basic configurator --> [DEBUG] (f) dataFile = G:\dev\MyApplication\target\cobertura\cobertura.ser [DEBUG] (f) forceMojoExecution = false [DEBUG] (f) maxmem = 64m [DEBUG] (f) mojoExecution = org.codehaus.mojo:cobertura-maven-plugin:2.6:check {execution: default-cli} [DEBUG] (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:compile, org.mortbay.jetty:jetty:jar:6.1.14:compile, org.mortbay.jetty:jetty-util:jar:6.1.14:compile, com.sun:tools:jar:0:system, log4j:log4j:jar:1.2.9:compile, 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] [DEBUG] (f) project = MavenProject: com.mycompany:MyApplication1.0.0 @ G:\dev\MyApplication\pom.xml [DEBUG] (f) quiet = false [DEBUG] (f) skip = false [DEBUG] -- end configuration --
我没有看到任何明显错误的内容,所以我不确定为什么我无法运行check
。
我正在运行RAD 8.5的嵌入式版本,使用具有此目标的运行配置:
清洁cobertura:检查
如果我将构建作为
运行清洁cobertura:cobertura
检查过程没有运行,构建成功,即使我知道我的覆盖率低于85%。
有谁知道cobertura:check
出了什么问题,以及我如何让它发挥作用?
答案 0 :(得分:0)
似乎正确的做法是将Maven称为目标:clean verify site
。
答案 1 :(得分: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>
这对我有用