JaCoCo prepare-agent goal doesn't update already defined property

637 views
Skip to first unread message

renan....@gmail.com

unread,
Feb 3, 2018, 10:47:47 AM2/3/18
to JaCoCo and EclEmma Users
I defined a custom property name for the JaCoCo agent but the prepare-agent goal doesn't update the value of the custom property if it is already defined.

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

Evgeny Mandrikov

unread,
Feb 3, 2018, 2:16:02 PM2/3/18
to JaCoCo and EclEmma Users
Hi,

In your case jacoco-maven-plugin updates property, but maven-surefire-plugin doesn't use this update.


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.

So replace in your pom.xml "${coverageAgent}" by "@{coverageAgent}".

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


P.S. please be aware that the standard courtesies (Hi, Thanks, ...) are always appreciated in this and other mailing lists.

renan....@gmail.com

unread,
Feb 3, 2018, 6:19:47 PM2/3/18
to JaCoCo and EclEmma Users
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.

Благодарю!

Evgeny Mandrikov

unread,
Feb 5, 2018, 1:53:06 PM2/5/18
to JaCoCo and EclEmma Users


On Sunday, February 4, 2018 at 12:19:47 AM UTC+1, renan....@gmail.com wrote:
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.



You can use another way that is also described on page at http://www.jacoco.org/jacoco/trunk/doc/prepare-agent-mojo.html :

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>


Or you can move both jacoco-maven-plugin and maven-surefire-plugin with late property evaluation into a profile that won't be active for IDE.

Renan Vinícius Mozone

unread,
Feb 5, 2018, 9:27:06 PM2/5/18
to jac...@googlegroups.com
Hi. As you suggested, I ended up creating a separate Maven profile to my IDE. The first option wasn't good for me because my IDE needs the explicit argLine configuration for the surefire plugin.

What I couldn't figure out is why surefire successfully gets my custom property (coverageAgent) if it is not declared under the properties tag. I this scenario, the JaCoCo prepare-agent goal defines the property and surefire "sees" it.

Anyway, thanks for the help.

--
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.
--
[]s
Renan
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages