unitsofmeasurement / unit-api

Units of Measurement API
http://unitsofmeasurement.github.io/unit-api/
Other
180 stars 42 forks source link

JaCoCo plugin fails with no coverage #161

Closed keilw closed 5 years ago

keilw commented 5 years ago

At least on Windows following the JUnit 5 migration (#154) the JaCoCo plugin fails: [INFO] --- jacoco-maven-plugin:0.8.2:check (post-unit-test) @ unit-api --- [INFO] Loading execution data file C:\Users\werner\git\unit-api\target\jacoco.exec [INFO] Analyzed bundle 'unit-api' with 15 classes [WARNING] Rule violated for bundle unit-api: instructions covered ratio is 0.0, but expected minimum is 0.5 [WARNING] Rule violated for bundle unit-api: complexity covered ratio is 0.0, but expected minimum is 0.5 [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 29.090 s [INFO] Finished at: 2019-01-20T18:08:10+01:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.2:check (post-unit-test) on project unit-api: Coverage checks have not been met. See log for details. -> [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/MojoExecutionException

teobais commented 5 years ago

Tweeted about it yesterday. Heard nothing back. Perhaps useful to post a question to StackOverflow as well.

teobais commented 5 years ago

Re-tweeted and also posted a SO question about it, which seems to be bringing us to a lead soon!

Let's see how it goes.

Oliver-Loeffler commented 5 years ago

Hi, so I am playing with it using Windows 8.1 and OpenJDK11 together mith Maven 3.5. Running the following Maven build provides me following results, just collecting all warnings and possible indications of errors here, not sure yet of those are directly related:

>mvn clean verify site
[INFO] Executing tasks

main:
    [mkdir] Created dir: D:\Unit-API\unit-api\target\classes\META-INF\versions\9
    [javac] Compiling 2 source files to D:\Unit-API\unit-api\target\classes\META-INF\versions\9
[INFO] Executed tasks
[INFO] 
[INFO] --- maven-bundle-plugin:3.4.0:bundle (default-bundle) @ unit-api ---
[WARNING] Bundle javax.measure:unit-api:bundle:2.0-SNAPSHOT :
 Invalid package name: 'META-INF.versions.9.javax.measure.spi'
[WARNING] Bundle javax.measure:unit-api:bundle:2.0-SNAPSHOT : 
 Invalid package name: 'META-INF.versions.9'
[WARNING] Bundle javax.measure:unit-api:bundle:2.0-SNAPSHOT : 
 Classes found in the wrong directory: 
{META-INF/versions/9/javax/measure/spi/ServiceProvider$Selector.class=javax.measure.spi.ServiceProvider$Selector, 
META-INF/versions/9/javax/measure/spi/ServiceProvider.class=javax.measure.spi.ServiceProvider, 
META-INF/versions/9/module-info.class=module-info}

...lots of info...

[INFO] 
[INFO] --- maven-surefire-plugin:2.22.0:test (default-test) @ unit-api ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.2:report (post-unit-test) @ unit-api ---
[INFO] Loading execution data file D:\Unit-API\unit-api\target\jacoco.exec
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.234 s
[INFO] Finished at: 2019-01-26T20:04:27+01:00
[INFO] Final Memory: 54M/1024M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.7.1:site (default-site) on project unit-api: failed to get report for org.apache.maven.plugins:maven-surefire-report-plugin: Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.2:report (post-unit-test) on project unit-api: An error has occurred in JaCoCo report generation.: Error while creating report: Error while analyzing D:\Unit-API\unit-api\target\classes\META-INF\versions\9\javax\measure\spi\ServiceProvider$Selector.class. Can't add different class with same name: javax/measure/spi/ServiceProvider$Selector -> [Help 1]
[ERROR] 

An interesting point is the error text:

Error while creating report: Error while analyzing 
D:\Unit-API\unit-api\target\classes\META-INF\versions\9\javax\measur\spi\ServiceProvider$Selector.class. 
Can't add different class with same name: javax/measure/spi/ServiceProvider$Selector

What exists is the report in target\site\jacoco, also target\jacoco.exec. The CSV and XML files are empty, the HTML report shows an overall coverage of 84%. I am not sure, but the error message point to the SPI mechanism and setup.

Oliver-Loeffler commented 5 years ago

Well, same results for Oracle JDK9, Oracle JDK8 does not work at all. I never built a multi release POM file yet but, I will look into exactly that.

Oliver-Loeffler commented 5 years ago

Hello, it seems definitely related to the multi-release JAR file structure. I have added following lines to the Jacoco Plugin configuration and then suddenly everything worked:

<configuration>
      <excludes>
        <exclude>META-INF/**</exclude>
      </excludes>
</configuration>

By excluding all classes located in META-INF from Jacoco analysis the issue is gone. See Jacoco issue: https://github.com/jacoco/jacoco/issues/407

The following source shows the full configuration of Jacoco-plugin. With that applied, I get builds using Oracle JDK9 and OpenJDK11 on Windows 8.1.

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>${jacoco.plugin.version}</version>
    <configuration>
      <excludes>
        <exclude>META-INF/**</exclude>
      </excludes>
    </configuration>
    <executions>
        <execution>
            <id>pre-unit-test</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>post-unit-test</id>
            <phase>test</phase>
            <goals>
                <goal>report</goal>
                <goal>check</goal>
            </goals>
            <configuration>
                <rules>
                    <rule>
                        <element>BUNDLE</element>
                        <limits>
                            <limit implementation="org.jacoco.report.check.Limit">
                                <counter>INSTRUCTION</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>0.5</minimum>
                            </limit>
                            <limit>
                                <counter>COMPLEXITY</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>0.5</minimum>
                            </limit>
                        </limits>
                    </rule>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>
michael-simons commented 5 years ago

Seems to be another issue @Oliver-Loeffler than the one I described here https://github.com/unitsofmeasurement/unit-api/pull/169.

I don't know what the site goal does, but it breaks on JDK 9 to 11 on Mac and Windows, with or without my fix. Works with yours, though.

I think both are needed.

Oliver-Loeffler commented 5 years ago

There is now a PR for this one too.

keilw commented 5 years ago

It works, thanks @Oliver-Loeffler, @thodorisbais and others who helped. Closing it.