【问题标题】:Cobertura coverage failingCobertura 覆盖失败
【发布时间】:2021-06-23 17:40:31
【问题描述】:

我遇到了类似于 [https://stackoverflow.com/questions/25432810/error-when-trying-to-use-org-codehaus-mojocobertura-maven-plugin2-6] 的问题。

日志: 执行目标 org.codehaus.mojo:cobertura-maven-plugin:2.6:instrument 的 default-cli 失败:插件 org.codehaus.mojo:cobertura-maven-plugin:2.6 或其依赖项之一无法解析:找不到工件 com.sun:tools:jar:0 在指定路径 /usr/local/Cellar/openjdk/15.0.2/libexec/openjdk.jdk/Contents/Home/../lib/tools.jar

研究:

当我执行java --version 时,我得到: java 11.0.6 2020-01-14 LTS

在搜索 SO 时,我发现由于我在 JDK 11 上,tools.jar 已被删除 [https://stackoverflow.com/a/60549167/13241701]。当我运行 jacoco 时,测试用例运行。但是

问题:我只想报告 cobertura 覆盖率报告。

我能得到一些帮助吗?

【问题讨论】:

    标签: java jacoco cobertura


    【解决方案1】:

    我建议使用最新版本的插件,它是 2.7,并内置了针对 java 11 的修复程序。

    如果你因为某些原因不能使用最新的插件,这里有一些你可以尝试的方法

    使用 'mvn dependency:tree' 查找该 jar 的调用位置并像这样排除它

    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>${struts2.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>tools</artifactId>
                <groupId>com.sun</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    
    

    或者你可以在你的 mvn 中引用它

    <dependency>
       <groupId>com.sun</groupId>
       <artifactId>tools</artifactId>
       <version>1.6</version>
       <scope>system</scope>
       <systemPath>C:\Program Files\Java\jdk1.11.6\lib\tools.jar</systemPath>
     </dependency>
    

    系统路径链接到您的库的位置

    另一种方法是提供 jdk vm 作为运行参数

    -vm "C:\Program Files\Java\jdk1.11.6\bin"
    

    【讨论】:

    • 仍然得到:Failed to execute goal org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument (default-cli) on project fb-connector: Execution default-cli of goal org.codehaus.mojo:cobertura-maven-plugin:2.7:instrument failed: Plugin org.codehaus.mojo:cobertura-maven-plugin:2.7 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:0 at specified path /usr/local/Cellar/openjdk/15.0.2/libexec/openjdk.jdk/Contents/Home/../lib/tools.jar mvn dependency:tree 未显示 com.sun。此外,我在mac上。谢谢
    猜你喜欢
    • 1970-01-01
    • 2013-02-03
    • 2018-07-08
    • 2017-01-03
    • 2010-11-14
    • 1970-01-01
    • 1970-01-01
    • 2014-05-30
    • 2013-05-28
    相关资源
    最近更新 更多