27

In our project we use jacoco-maven-plugin and during the build I get this error:

[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:check (jacoco-check) on project my-project: Coverage checks have not been met. See log for details. 

I know that it's better to fix coverage and so on. But sometimes I just need to quickly build a project. Is there some kind of parameter for this purpose? Like mvn clean install -Dskip.jacoco.check=true or other way to quickly skip this check?

Wlad
  • 2,866
  • 3
  • 28
  • 42
IKo
  • 4,998
  • 8
  • 34
  • 54
  • 7
    Yes. Almost like that. The check goal has a skip parameter: https://www.eclemma.org/jacoco/trunk/doc/check-mojo.html#skip - so it would be -Djacoco.skip=true - it seems this skips all of the jacoco goals. If you don't want that maybe temporarily move the check goal into a profile you can activate when back on track? – wemu Feb 11 '20 at 09:13
  • @wemu Can you put your comment into an official answer? I find it also works for me – Truong Aug 20 '20 at 10:26
  • 1
    @wemu 's comment worked for me, too. I posted it as answer below. All the credits go to him :))) – Wlad Aug 27 '20 at 16:51
  • 1
    @IKo I'd also add the tags `Jacoco` and `skip` – Wlad Aug 27 '20 at 17:39
  • You may preserve coverage checking and continue build. See `jacoco:check` parameter: [haltOnFailure](https://www.jacoco.org/jacoco/trunk/doc/check-mojo.html#haltOnFailure). Set it up in your `pom.xml` or use a ` mvn jacoco:check -Djacoco.haltOnFailure=false` – Dimio Nov 09 '22 at 12:58

4 Answers4

44

As @wemu commented below OP u can use -Djacoco.skip=true command line option to skip Jacoco code instrumentation and coverage report generation temporarily. Examples:

mvn clean test -Djacoco.skip=true
mvn clean verify -Djacoco.skip=true
mvn clean package -Djacoco.skip=true
mvn clean install -Djacoco.skip=true
Wlad
  • 2,866
  • 3
  • 28
  • 42
1

You can skip code coverage for some java files using pom.xml or else sonar-project.properties.

Ex: use the below plugin, give the packages of java files which does not require code coverage in the tag

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.5</version>
    <executions>
        <execution>
            <id>default-prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>default-report</id>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
        <execution>
            <id>default-check</id>
            <goals>
                <goal>check</goal>
            </goals>
            <configuration>
                <excludes>
                    <exclude>com/sbi/mdcm/v1_0_0/insurancequote/autogen/**</exclude>
                    <exclude>com/sbi/mdcm/v1_0_0/insurancequote_resources/autogen/**</exclude>
                </excludes>
                <rules>
                    <rule>
                        <element>BUNDLE</element>
                        <limits>
                            <limit>
                                <counter>COMPLEXITY</counter>
                                <value>COVEREDRATIO</value>
                                <minimum>0.80</minimum>
                            </limit>
                        </limits>
                    </rule>
                </rules>
            </configuration>
        </execution>
    </executions>
</plugin>
        

sonar-project.properties:

sonar.exclusions=**/com/sbi/mdcm/v1_0/insurancepolicy_adapter/osi/model/*.java
Matt Ke
  • 3,599
  • 12
  • 30
  • 49
durgaPrasad
  • 109
  • 1
  • 3
  • 12
  • Beeing able to exclude classes can be useful, especially if they are conflicting w/ Jacoco and make the build fail. This is not what OP asked for, though. – Wlad Aug 27 '20 at 16:57
1

You can set jacoco.haltOnFailure property to false when executing build and this will do the checks but will not fail the build.

Example:

mvn clean install -Djacoco.haltOnFailure=false

Docs are here.

Piotr Chowaniec
  • 1,160
  • 12
  • 25
0

Using @Wlad's answer above, I made a simple batch script over the MVN command. I set the default behavior, since this is for my development environment, to disable/skip the Jacoco coverage analysis. Create this script in your %MVN_HOME\bin% directory. Adjust for your preferences:

m.bat:

@echo off

@REM Facade over maven command

if [%1]==[-j] goto jacoco
echo Skipping Jacoco analysis
mvn %1 %2 %3 %4 %5 %6 %7 -Djacoco.skip=true
goto end
:jacoco
mvn %2 %3 %4 %5 %6 %7

:end

This allows the following invocations:

  • for code coverage: m -j clean site
  • and to build my package (no code coverage): m clean package

Flavor to your liking. :-)

dan
  • 741
  • 9
  • 14