mardi 15 mai 2018

Is it possible to only run the JaCoCo maven plugin during the site lifecycle?

Consider the follow build configuration:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <argLine>${surefireArgLine}</argLine>
      <parallel>all</parallel>
      <threadCount>2</threadCount>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
      <argLine>${failsafeArgLine}</argLine>
      <parallel>classes</parallel>
      <threadCount>2</threadCount>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>pre-unit-test</id>
        <goals>
          <goal>prepare-agent</goal>
        </goals>
        <configuration>
          <destFile>${project.build.directory}/jacoco-ut.exec</destFile>
          <propertyName>surefireArgLine</propertyName>
        </configuration>
      </execution>
      <execution>
        <id>post-unit-test</id>
        <phase>test</phase>
        <goals>
          <goal>report</goal>
        </goals>
        <configuration>
          <dataFile>${project.build.directory}/jacoco-ut.exec</dataFile>
        </configuration>
      </execution>
      <execution>
        <id>pre-integration-test</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>prepare-agent</goal>
        </goals>
        <configuration>
          <destFile>${project.build.directory}/jacoco-it.exec</destFile>
          <propertyName>failsafeArgLine</propertyName>
        </configuration>
      </execution>
      <execution>
        <id>post-integration-test</id>
        <phase>post-integration-test</phase>
        <goals>
          <goal>report</goal>
        </goals>
        <configuration>
          <dataFile>${project.build.directory}/jacoco-it.exec</dataFile>
        </configuration>
      </execution>
    </executions>
  </plugin>

And reporting configuration:

  <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <reportSets>
      <reportSet>
        <id>JaCoCo-UnitTest</id>
        <reports>
          <report>report</report>
        </reports>
        <configuration>
          <dataFile>${project.build.directory}/jacoco-ut.exec</dataFile>
        </configuration>
      </reportSet>
      <reportSet>
        <id>JaCoCo-IntegrationTest</id>
        <reports>
          <report>report</report>
        </reports>
        <configuration>
          <dataFile>${project.build.directory}/jacoco-it.exec</dataFile>
        </configuration>
      </reportSet>
    </reportSets>
  </plugin>

The awesome part is mvn clean site works awesome, I get my reports. However, this now means that the JaCoCo agent is starting during the normal lifecycle, ie: mvn clean install verify.

Is there a way to disable the JaCoCo agent during the normal lifecycle but not the site cycle?

Aucun commentaire:

Enregistrer un commentaire