2

We have JaCoCo working in our POM and it runs and reports every time we run clean install.

What we would really like to do is only run JaCoCo when a maven site is run.

I have tried adding:

...
<configuration>
<skip>${jacoco.skip}</skip>
....

And setting jacoco.skip to true for the build phase, but in the reporting section, I have added:

...
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>   
<configuration>
    <skip>false</skip>
    <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
...

But this does not work. Setting jacoco.skip to true does prevent JaCoCo running on normal maven clean install's but also appears to affect the reporting.

Question: How would I configure maven so that JaCoCo runs successfully for a maven site, but does not run for a mvn clean install?

4

1 に答える 1

2

最も簡単な方法は、それを Mavenプロファイルbuildに委任し、セクションの構成を削除して、次のようにプロファイルに配置することです。

<profiles>
    <profile>
        <id>jacoco</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.1.201405082137</version>
                    <configuration><!-- here --></configuration>
                </plugin>
            </plugins>
        </build>

        <reporting>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.1.201405082137</version>
                </plugin>
            </plugins>
        </reporting>
    </profile>
</profiles>

そこにカスタム構成を追加できます。

その後、通常のビルドでは適用されませんが、次の方法でいつでもアクティブ化できます。

mvn clean install -Pjacoco

また

mvn site -Pjacoco
于 2016-02-03T13:01:51.567 に答える