In my example below, the name of the custom property is coverageAgent.
The surefire plug-in is then configured to use the coverageAgent property as its argument line.
When surefire runs, its argument line doesn't contain the JaCoCo agent configuration.
-----------------------------------------
POM.xml
-----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.somecompany.bdo</groupId>
<artifactId>bdo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jacoco.propertyName>coverageAgent</jacoco.propertyName>
<coverageAgent/>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.0</version>
<executions>
<execution>
<id>jacoco-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<argLine>${coverageAgent}</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
-----------------------------------------
Maven output
-----------------------------------------
mvn -X clean test
...
[INFO] --- jacoco-maven-plugin:0.8.0:prepare-agent (jacoco-prepare-agent) @ bdo ---
...
[INFO] coverageAgent set to -javaagent:/home/rmozone/.m2/repository/org/jacoco/org.jacoco.agent/0.8.0/org.jacoco.agent-0.8.0-runtime.jar=destfile=/home/rmozone/workspace/git/bdoo/target/jacoco.exec
...
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ bdo ---
...
[DEBUG] Forking command line: /bin/sh -c cd /home/rmozone/workspace/git/bdoo && /usr/lib/jvm/java-8-oracle/jre/bin/java -jar /home/rmozone/workspace/git/bdoo/target/surefire/surefirebooter2531224102921618966.jar /home/rmozone/workspace/git/bdoo/target/surefire 2018-02-03T13-44-20_556-jvmRun1 surefire3724758252028070151tmp surefire_01835185317323397064tmp
If your project already defines VM arguments for test execution, be sure that they will include property defined by JaCoCo.One of the ways to do this in case of maven-surefire-plugin - is to use syntax for late property evaluation
Maven does property replacement for${...}values in pom.xml before any plugin is run. So Surefire would never see the place-holders in its argLine property.Since the Version 2.17 using an alternate syntax for these properties,@{...}allows late replacement of properties when the plugin is executed, so properties that have been modified by other plugins will be picked up correctly.
mvn clean test -X | grep "command line"[DEBUG] Forking command line: /bin/sh -c cd /tmp/j && /home/godin/.java-select/versions/jdk1.8.0_152/jre/bin/java -javaagent:/home/godin/.m2/repository/org/jacoco/org.jacoco.agent/0.8.0/org.jacoco.agent-0.8.0-runtime.jar=destfile=/tmp/j/target/jacoco.exec -jar /tmp/j/target/surefire/surefirebooter6907447922370012705.jar /tmp/j/target/surefire 2018-02-03T20-14-39_816-jvmRun1 surefire5242086529034299797tmp surefire_07205880708538677833tmp
Thanks for your time and your answer.
Happens that IntelliJ - as far as current version, 2017.3.4 - doesn't support late property evaluation.
They don't even have a plan to fix this (https://youtrack.jetbrains.com/issue/IDEA-143187).
I'm trying to find some way around this.
Another way is to define "argLine" as a Maven property rather than as part of the configuration of maven-surefire-plugin:<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>
--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/rS0zJhiKr24/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/7a4a7d5c-718d-46f4-933a-d42657e5d528%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.