Cobertura coverage failing

I am running into issues similar to [https://stackoverflow.com/questions/25432810/error-when-trying-to-use-org-codehaus-mojocobertura-maven-plugin2-6].

LOGS: Execution default-cli of goal org.codehaus.mojo:cobertura-maven-plugin:2.6:instrument failed: Plugin org.codehaus.mojo:cobertura-maven-plugin:2.6 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

RESEARCH:

When I do java --version, I get: java 11.0.6 2020-01-14 LTS

Upon searching SO, I found that since I am on the JDK 11, the tools.jar has been removed [https://stackoverflow.com/a/60549167/13241701]. When I run the jacoco, the test cases run. But

ISSUE: I want to report the cobertura coverage report only.

Can I get some help?

1 answer

  • answered 2021-03-26 22:02 Abhilasha Gupta

    I would recommend using latest version of the plugin which is 2.7 and has built in fixes for java 11.

    If you cannot use latest plugin for some reason, here are some of the things you can try

    Use 'mvn dependency:tree' to find where that jar is being called and exclude it like so

    <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>
    
    

    Or you can just reference it in your mvn like

    <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>
    

    where system path is link to your lib

    Another way is to provide jdk vm as a run arg

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