1

To successfully run my unit tests I have to provide JVM with some replaced standard classes. Therefore, I use following configuration for maven-surefire-plugin :

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.19.1</version>
  <configuration>
    <skipTests>${skipUTs}</skipTests>
    <argLine>-Xbootclasspath/p:my.jar</argLine>
  </configuration>
</plugin>

plugin/configuration/argLine added, nothing special. But how can I tell jacoco the same thing? The jacoco doesn’t have configuration/argLine :( .

I have configured the Maven JaCoCo plugin as follows in my pom.xml file:

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.7.5.201505241946</version>
  <configuration>
    <skip>${skipUTs}</skip>
    <!-- NO ONE (((((
    <argLine>-Xbootclasspath/p:my.jar</argLine>
    -->
  </configuration>
  <executions>
    <execution>
      <id>default-prepare-agent</id>
      <goals>
        <goal>prepare-agent</goal>
      </goals>
    </execution>
    <execution>
      <id>default-report</id>
      <phase>prepare-package</phase>
      <goals>
        <goal>report</goal>
      </goals>
    </execution>
    <execution>
      <id>default-check</id>
      <goals>
        <goal>check</goal>
      </goals>
      <configuration>
        <rules>
          <rule implementation="org.jacoco.maven.RuleConfiguration">
            <element>BUNDLE</element>
            <limits>
              <limit implementation="org.jacoco.report.check.Limit">
                <counter>COMPLEXITY</counter>
                <value>COVEREDRATIO</value>
                <minimum>1.0</minimum>
              </limit>
            </limits>
          </rule>
        </rules>
      </configuration>
    </execution>
  </executions>
</plugin>
ieXcept
  • 1,088
  • 18
  • 37
  • Possible duplicate of [Cannot use jacoco JVM args and surefire JVM args together in maven](http://stackoverflow.com/questions/23190107/cannot-use-jacoco-jvm-args-and-surefire-jvm-args-together-in-maven) – Godin Dec 02 '16 at 18:05

1 Answers1

2

As stated in documentation of prepare-agent - it simply sets property argLine that is used by maven-surefire-plugin, and you have two options to add additional arguments:

<properties>
  <argLine>-your -extra -arguments</argLine>
</properties>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <!-- no argLine here -->
  </configuration>
</plugin>

or using late property evaluation feature of maven-surefire-plugin:

<properties>
  <!-- empty to avoid JVM startup error "Could not find or load main class @{argLine}" in case when jacoco-maven-plugin not executed -->
  <argLine></argLine>
</properties>
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>@{argLine} -your -extra -arguments</argLine>
  </configuration>
</plugin>
Godin
  • 9,801
  • 2
  • 39
  • 76