I am using maven with the jacoco plugin to generate code coverage metrics. I am having some difficulty in configuring the surefire plugin with the java opt
Update the POM.xml as
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.1</version>
<configuration>
<argLine>${argLine} -XX:PermSize=256m -XX:MaxPermSize=1048m</argLine>
</configuration>
</plugin>
and then the most important thing is to run the Maven project with goals: mvn jacoco:prepare-agent clean test jacoco:report
Try using
@{argLine}
instead of
${argLine}
(or surefire.argLine
in your case)
It allows surefire to read a property as modified by other plugins instead of reading the one substituted by Maven itself. Then you can set the argLine
param to empty in Maven properties:
<properties>
<argLine></argLine>
</properties>
Which now will not cause any problems. More here: How do I use properties set by other plugins in argLine?
I recently ran into the same issue and even took implicitly the same steps as you described with the same result. No clean solution I found worked for me.
So I ran several steps in debug mode and it seems that Maven replaces properties twice. That is not just in a lazy manner, as I thought, but in both eager and lazy manner:
properties
section of POM and probably also settings.xml),This is where our step with setting a blank property as a default failed. Maven just went:
Finally the solution is to set the default value dynamically. This can be done with GMaven plugin like this:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>set-default-values</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
project.properties.'surefire.argLine' = ''
</source>
</configuration>
</execution>
</executions>
</plugin>
So now Maven goes:
With active profile the exec file is generated, with non-active profile the blank default value is used and build succeeds.
My solution to use argLine in the maven-surefire-plugin safely.
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<id>set-custom-arg-line</id>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def argLine = project.properties['argLine'];
if (argLine == null) {
argLine = "";
}
project.properties.argLine = argLine;
</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx1024m ${argLine}</argLine>
</configuration>
</plugin>