surefire javaagent conflict

117 views
Skip to first unread message

eric....@gmail.com

unread,
Sep 19, 2019, 10:02:38 AM9/19/19
to JaCoCo and EclEmma Users
I am trying to get Jacoco to play nice with jMockit.  The issue is that jmockit requires that the javaagent to be modified like:

        <plugin>
               
<groupId>org.apache.maven.plugins</groupId>
               
<artifactId>maven-surefire-plugin</artifactId>
               
<configuration>
                   
<forkCount>1</forkCount>
                   
<runOrder>random</runOrder>
                   
<argLine>@{argLine}
                        -javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar
                   
</argLine>
               
</configuration>
           
</plugin>

unfortunately adding the @{argLine} removes the -javaagent line required by jmockit.  I have also tried using ${argLine} as a property but the same thing happens.  Is there a way for the Jacoco -javaagent line to include my jmockit requirements as well?

Thank you!

Marc Hoffmann

unread,
Sep 20, 2019, 2:16:55 AM9/20/19
to jac...@googlegroups.com
Hi,

have you tried to run the exact same code without @{argLine}?

The quotes within the arguments of the JMockit agent look suspicious to me. I’m not sure whether the JVM can handle this.

Please run your Maven build in debug mode (-X option) and check how the effective command line looks like.

Regards,
-marc

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/c7b4f84b-9bb3-411f-b16c-c71736ea15a7%40googlegroups.com.

eric....@gmail.com

unread,
Sep 20, 2019, 8:49:13 AM9/20/19
to JaCoCo and EclEmma Users
It runs fine without the @{argLine}, but then jacoco does not report coverage. The quotes are not an issue.


On Friday, September 20, 2019 at 2:16:55 AM UTC-4, Marc R. Hoffmann wrote:
Hi,

have you tried to run the exact same code without @{argLine}?

The quotes within the arguments of the JMockit agent look suspicious to me. I’m not sure whether the JVM can handle this.

Please run your Maven build in debug mode (-X option) and check how the effective command line looks like.

Regards,
-marc
On 19. Sep 2019, at 16:02, eric....@gmail.com wrote:

I am trying to get Jacoco to play nice with jMockit.  The issue is that jmockit requires that the javaagent to be modified like:

        <plugin>
               
<groupId>org.apache.maven.plugins</groupId>
               
<artifactId>maven-surefire-plugin</artifactId>
               
<configuration>
                   
<forkCount>1</forkCount>
                   
<runOrder>random</runOrder>
                   
<argLine>@{argLine}
                        -javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar
                   
</argLine>
               
</configuration>
           
</plugin>

unfortunately adding the @{argLine} removes the -javaagent line required by jmockit.  I have also tried using ${argLine} as a property but the same thing happens.  Is there a way for the Jacoco -javaagent line to include my jmockit requirements as well?

Thank you!

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jac...@googlegroups.com.

Evgeny Mandrikov

unread,
Sep 20, 2019, 9:29:35 AM9/20/19
to JaCoCo and EclEmma Users

"@{argLine}" is a feature of maven-surefire-plugin called late property evaluation ( http://maven.apache.org/surefire/maven-surefire-plugin/faq.html#late-property-evaluation ),
which is available only in maven-surefire-plugin versions starting from 2.17 - see https://issues.apache.org/jira/browse/SUREFIRE-1047

So which version of maven-surefire-plugin do you use?

Also as written in JaCoCo documentation on page https://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>

eric....@gmail.com

unread,
Sep 20, 2019, 9:39:10 AM9/20/19
to JaCoCo and EclEmma Users
Thanks,
I am running the latest version of sure fire (tried 2.22.1 and 3). Yes I tried replacing it as an argLine propertly. 

The issue is not with surefire.  @{argLine} works.  The issue is that jmockit requires a javaagent to be set.  when jacoco replaces the argline with it's own javaagent it replaces the one set by jmockit.  I can only get jacoco working, but then jmockit fails, or jmockit but then jacoco fails.  I am trying to get both to play nicely with each other. when this runs the command line to java does not include the jmockit javaagent line below. It gets replaced by the argLine set by jacoco.

    <plugin>
               
<groupId>org.apache.maven.plugins</groupId>
               
<artifactId>maven-surefire-plugin</artifactId>
               
<configuration>
                   
<forkCount>1</forkCount>
                   
<runOrder>random</runOrder>
                   
<argLine>@{argLine}
                        -javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar
                   
</argLine>
               
</configuration>
           
</plugin>

Marc Hoffmann

unread,
Sep 20, 2019, 9:44:11 AM9/20/19
to JaCoCo and EclEmma Users
Ok, and how exactly does the “conflict” look like? What happens?


To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/6641c54e-5695-4119-8139-7c985ef0d0f9%40googlegroups.com.

Evgeny Mandrikov

unread,
Sep 20, 2019, 9:48:11 AM9/20/19
to jac...@googlegroups.com
jacoco-maven-plugin goal prepare-agent modifies property by prepending new value,
it has no way to overwrite configuration of maven-surefire-plugin

In example.zip attachment you'll find full example,
whose execution with full debug log as

mvn -X verify

clearly shows that maven-surefire-plugin executes java with both agents:

java -javaagent:/Users/evgeny.mandrikov/.m2/repository/org/jacoco/org.jacoco.agent/0.8.4/org.jacoco.agent-0.8.4-runtime.jar=destfile=/private/tmp/j/example/target/jacoco.exec -javaagent:/Users/evgeny.mandrikov/.m2/repository/org/jmockit/jmockit/1.48/jmockit-1.48.jar

if this doesn't work for you, then
in order to not waste time on blind guessing
please provide complete example that demonstrates your difficulty.


To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/fdef9118-35e7-47e4-bf31-f422bf541dfd%40googlegroups.com.
example.zip

eric....@gmail.com

unread,
Sep 20, 2019, 10:35:13 AM9/20/19
to JaCoCo and EclEmma Users
Thanks for sending that. It happens if you change to java 11.  sorry doesn't seem I can attach a file here. just change these lines in the pom.xml
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>


if you run mvn clean package
you can see the javaagent set to
[INFO] --- jacoco-maven-plugin:0.8.4:prepare-agent (default) @ example ---
[INFO] argLine set to -javaagent:/home/eric/.m2/repository/org/jacoco/org.jacoco.agent/0.8.4/org.jacoco.agent-0.8.4-runtime.jar=destfile=/home/eric/Documents/example/target/jacoco.exec
the tests will fail.

if you remove @{argLine} the tests pass again

Evgeny Mandrikov

unread,
Sep 20, 2019, 11:07:28 AM9/20/19
to JaCoCo and EclEmma Users
This has nothing to do with "argLine".
In case of Java 11 bytecode your test fails because of the following bug in JMockit - https://github.com/jmockit/jmockit1/issues/615#issuecomment-501009439

eric....@gmail.com

unread,
Sep 20, 2019, 11:41:22 AM9/20/19
to JaCoCo and EclEmma Users
I can't thank you enough.  That is it.  Sorry if I spun your wheels.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages