我正在尝试使用Cobertura maven插件进行代码覆盖。但是在运行以下命令时出现错误:
mvn clean package cobertura:cobertura -Dcobertura.report.format=xml
以下是我在pom.xml中定义插件的方法:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
<formats>
<format>xml</format>
</formats>
<instrumentation>
<excludes>
<include>**/*.class</include>
<exclude>**/*Test.class</exclude>
<exclude>**/Test*.class</exclude>
</excludes>
</instrumentation>
</configuration>
</plugin>
这是我收到的错误:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:09.201s
[INFO] Finished at: Thu Aug 21 17:28:24 GMT+00:00 2014
[INFO] Final Memory: 25M/64M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:cobertura-maven-plugin:2.6:instrument (default-cli) on project project-beta: Execution default-cli of goal org.codehaus.mojo:cobertura-maven-plugin:2.6:instrument failed: A required class was missing while executing org.codehaus.mojo:cobertura-maven-plugin:2.6:instrument: net/sourceforge/cobertura/util/CommandLineBuilder
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.codehaus.mojo:cobertura-maven-plugin:2.6
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/data/home/user/.m2/repository/org/codehaus/mojo/cobertura-maven-plugin/2.6/cobertura-maven-plugin-2.6.jar
[ERROR] urls[1] = file:/data/home/user/.m2/repository/net/sourceforge/cobertura/cobertura/2.0.3/cobertura-2.0.3.jar
[ERROR] urls[2] = file:/data/home/user/.m2/repository/org/ow2/asm/asm/4.1/asm-4.1.jar
[ERROR] urls[3] = file:/data/home/user/.m2/repository/org/ow2/asm/asm-tree/4.1/asm-tree-4.1.jar
[ERROR] urls[4] = file:/data/home/user/.m2/repository/org/ow2/asm/asm-commons/4.1/asm-commons-4.1.jar
[ERROR] urls[5] = file:/data/home/user/.m2/repository/org/ow2/asm/asm-util/4.1/asm-util-4.1.jar
[ERROR] urls[6] = file:/data/home/user/.m2/repository/org/ow2/asm/asm-analysis/4.1/asm-analysis-4.1.jar
[ERROR] urls[7] = file:/data/home/user/.m2/repository/oro/oro/2.0.8/oro-2.0.8.jar
[ERROR] urls[8] = file:/data/home/user/.m2/repository/jaxen/jaxen/1.1-beta-8/jaxen-1.1-beta-8.jar
[ERROR] urls[9] = file:/data/home/user/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar
[ERROR] urls[10] = file:/data/home/user/.m2/repository/jdom/jdom/1.0/jdom-1.0.jar
[ERROR] urls[11] = file:/data/home/user/.m2/repository/xerces/xmlParserAPIs/2.6.2/xmlParserAPIs-2.6.2.jar
[ERROR] urls[12] = file:/data/home/user/.m2/repository/xerces/xercesImpl/2.6.2/xercesImpl-2.6.2.jar
[ERROR] urls[13] = file:/data/home/user/.m2/repository/xom/xom/1.0b3/xom-1.0b3.jar
[ERROR] urls[14] = file:/data/home/user/.m2/repository/com/ibm/icu/icu4j/2.6.1/icu4j-2.6.1.jar
[ERROR] urls[15] = file:/data/home/user/.m2/repository/xalan/xalan/2.6.0/xalan-2.6.0.jar
[ERROR] urls[16] = file:/data/home/user/.m2/repository/org/ccil/cowan/tagsoup/tagsoup/0.9.7/tagsoup-0.9.7.jar
[ERROR] urls[17] = file:/data/home/user/.m2/repository/org/apache/ant/ant/1.8.3/ant-1.8.3.jar
[ERROR] urls[18] = file:/data/home/user/.m2/repository/org/apache/ant/ant-launcher/1.8.3/ant-launcher-1.8.3.jar
[ERROR] urls[19] = file:/data/home/user/.m2/repository/org/mortbay/jetty/servlet-api-2.5/6.1.14/servlet-api-2.5-6.1.14.jar
[ERROR] urls[20] = file:/data/home/user/.m2/repository/org/mortbay/jetty/jetty/6.1.14/jetty-6.1.14.jar
[ERROR] urls[21] = file:/data/home/user/.m2/repository/org/mortbay/jetty/jetty-util/6.1.14/jetty-util-6.1.14.jar
[ERROR] urls[22] = file:/data/java/jdk1.7.0_45/jre/../lib/tools.jar
[ERROR] urls[23] = file:/data/home/user/.m2/repository/log4j/log4j/1.2.9/log4j-1.2.9.jar
[ERROR] urls[24] = file:/data/home/user/.m2/repository/net/sourceforge/cobertura/cobertura-runtime/2.0.3/cobertura-runtime-2.0.3.pom
[ERROR] urls[25] = file:/data/home/user/.m2/repository/urbanophile/java-getopt/1.0.9/java-getopt-1.0.9.jar
[ERROR] urls[26] = file:/data/home/user/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.jar
[ERROR] urls[27] = file:/data/home/user/.m2/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar
[ERROR] urls[28] = file:/data/home/user/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.8/maven-reporting-api-2.0.8.jar
[ERROR] urls[29] = file:/data/home/user/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-9/doxia-sink-api-1.0-alpha-9.jar
[ERROR] urls[30] = file:/data/home/user/.m2/repository/org/apache/maven/reporting/maven-reporting-impl/2.0.4.2/maven-reporting-impl-2.0.4.2.jar
[ERROR] urls[31] = file:/data/home/user/.m2/repository/commons-validator/commons-validator/1.2.0/commons-validator-1.2.0.jar
[ERROR] urls[32] = file:/data/home/user/.m2/repository/commons-beanutils/commons-beanutils/1.7.0/commons-beanutils-1.7.0.jar
[ERROR] urls[33] = file:/data/home/user/.m2/repository/commons-digester/commons-digester/1.6/commons-digester-1.6.jar
[ERROR] urls[34] = file:/data/home/user/.m2/repository/commons-logging/commons-logging/1.0.4/commons-logging-1.0.4.jar
[ERROR] urls[35] = file:/data/home/user/.m2/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar
[ERROR] urls[36] = file:/data/home/user/.m2/repository/org/apache/maven/doxia/doxia-core/1.0/doxia-core-1.0.jar
[ERROR] urls[37] = file:/data/home/user/.m2/repository/org/apache/maven/doxia/doxia-site-renderer/1.0/doxia-site-renderer-1.0.jar
[ERROR] urls[38] = file:/data/home/user/.m2/repository/org/codehaus/plexus/plexus-i18n/1.0-beta-7/plexus-i18n-1.0-beta-7.jar
[ERROR] urls[39] = file:/data/home/user/.m2/repository/org/codehaus/plexus/plexus-velocity/1.1.7/plexus-velocity-1.1.7.jar
[ERROR] urls[40] = file:/data/home/user/.m2/repository/org/apache/velocity/velocity/1.5/velocity-1.5.jar
[ERROR] urls[41] = file:/data/home/user/.m2/repository/org/apache/maven/doxia/doxia-decoration-model/1.0/doxia-decoration-model-1.0.jar
[ERROR] urls[42] = file:/data/home/user/.m2/repository/commons-collections/commons-collections/3.2/commons-collections-3.2.jar
[ERROR] urls[43] = file:/data/home/user/.m2/repository/org/apache/maven/doxia/doxia-module-apt/1.0/doxia-module-apt-1.0.jar
[ERROR] urls[44] = file:/data/home/user/.m2/repository/org/apache/maven/doxia/doxia-module-fml/1.0/doxia-module-fml-1.0.jar
[ERROR] urls[45] = file:/data/home/user/.m2/repository/org/apache/maven/doxia/doxia-module-xdoc/1.0/doxia-module-xdoc-1.0.jar
[ERROR] urls[46] = file:/data/home/user/.m2/repository/org/apache/maven/doxia/doxia-module-xhtml/1.0/doxia-module-xhtml-1.0.jar
[ERROR] urls[47] = file:/data/home/user/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar
[ERROR] urls[48] = file:/data/home/user/.m2/repository/org/codehaus/plexus/plexus-utils/2.0.2/plexus-utils-2.0.2.jar
[ERROR] urls[49] = file:/data/home/user/.m2/repository/org/apache/maven/shared/maven-invoker/2.0.11/maven-invoker-2.0.11.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------: net.sourceforge.cobertura.util.CommandLineBuilder
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
Build step 'Invoke top-level Maven targets' marked build as failure
Skipping Cobertura coverage report as build was not UNSTABLE or better ...
Finished: FAILURE
我已经清除了我的本地存储库并尝试再次运行它,但没有运气。
还有其他建议吗?
我使用的是Maven 3.1.0和Java 1.7.0_45
更新
我使用Nexus作为回购经理。查看日志,我看到:
[INFO] Failed to parse Maven artifact /data/home/user/sonatype-work/nexus/storage/central/net/sourceforge/cobertura/cobertura/2.0.3/cobertura-2.0.3.jar due to invalid CEN header (bad signature)
这似乎表明这个罐子已经腐败了。但我一直试图从Maven Central重新下载它。还是卡住了。
答案 0 :(得分:1)
使用: -
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<reportSets>
<reportSet>
<reports>
<report>cobertura</report>
</reports>
</reportSet>
</reportSets>
</configuration>
</plugin>
答案 1 :(得分:1)
我也遇到了这个问题,这个问题与Maven中的Java版本有关。您的系统中可能有多个JDK版本,或者您的Maven引用了其他一些JDK版本。
因此,首先您可以通过在maven项目目录中键入以下命令来检查Maven和引用版本。
mvn -v
ITSs-MacBook-Pro:工作台vshah $ mvn -v Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)Maven主页: /usr/local/Cellar/maven/3.6.3_1/libexec Java版本:1.8.0_241, 供应商:Oracle Corporation,运行时: /图书馆/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home/jre 默认语言环境:en_GB,平台编码:UTF-8操作系统名称:“ mac os x”, 版本:“ 10.14.3”,拱门:“ x86_64”,家族:“ mac”
并检查Maven和JDK版本。如果发现maven的JDK版本未引用必需的JDK版本,则需要检查JAVA_HOME路径。如果您正确设置了JAVA_HOME路径,那么它肯定会起作用。
答案 2 :(得分:0)
请检查您的路径变量。 您可能将其指向jre bin路径,它应该指向jdk bin。 我有同样的问题,我做了上面的解决方案,它对我有用。
答案 3 :(得分:0)
如果你们在执行描述性作业时使用jenkins并遇到问题,则还要检查配置,
如果您已在“全局工具配置”中为maven和Java选择了“自动安装”选项,请取消选择它,然后手动添加在jenkins服务器上安装maven和java的目录。
答案 4 :(得分:-1)
尝试从外部站点下载并将其放置在本地存储库中。
答案 5 :(得分:-2)
最重要的一行是A required class was missing while executing org.codehaus.mojo:cobertura-maven-plugin:2.6:instrument: net/sourceforge/cobertura/util/CommandLineBuilder
。
验证包含此类的jar(即文件:/data/home/user/.m2/repository/net/sourceforge/cobertura/cobertura/2.0.3/cobertura-2.0.3.jar)是否已损坏。是这样,将其从本地存储库中删除。如果您正在使用Repository Manager,请验证它是否也已损坏并需要删除。接下来再试一次。