Maven site integration for projects with offline instrumentation

332 views
Skip to first unread message

fwie...@gmail.com

unread,
Apr 19, 2016, 7:42:22 AM4/19/16
to JaCoCo and EclEmma Users
Hi,

In our project we use offline instrumentation as we are doing AspectJ compile-time weaving. The report generated by the Maven report goal is accurate (although we use PowerMockito), but it is currently generated from the Maven default lifecycle, not the site lifecycle:
<profile>
<id>jacoco-coverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<!-- our excludes -->
</excludes>
</configuration>
<executions>
<execution>
<id>offline-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>restore-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>


Now, when I invoke mvn clean install site -P jacoco-coverage, this of course leads to the JaCoCo report not being shown under Project Reports.
On the other hand, adding

<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>

leads to JaCoCo attempting another instrumentation of the classes in the site rendering phase, which then fails.

Is there a way to tell the jacoco-maven-plugin to not perform a second report generation, if there is already a generated report in the build sequence, so that it only attaches it as site artifact?


Thank you!
Florian

Mirko Friedenhagen

unread,
Apr 19, 2016, 12:51:29 PM4/19/16
to jac...@googlegroups.com

Hello Florian,

did you put the reporting section into the profile as well? This should just work AFAIK.

Regards
Mirko
--
Sent from my mobile

--
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/82e705e3-1694-44ec-89f4-2fbdc42c5642%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Florian Wiesner

unread,
Apr 20, 2016, 5:59:40 AM4/20/16
to jac...@googlegroups.com
Looks like I was able to isolate the problem:

[INFO] configuring report plugin org.apache.maven.plugins:maven-surefire-report-plugin:2.19.1

[INFO] preparing 'report' report requires '[surefire]test' forked phase execution

[INFO] 

[INFO] >>> maven-surefire-report-plugin:2.19.1:report > [surefire]test @ PROJECT >>>

[INFO] 

[INFO] --- xmlbeans-maven-plugin:2.3.3:xmlbeans (default) @ PROJECT ---

[INFO] All schema objects are up to date.

[INFO] 

[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ PROJECT ---

[INFO] Using 'utf-8' encoding to copy filtered resources.

[INFO] Copying 7 resources

[INFO] Copying 103 resources

[INFO] Copying 103 resources

[INFO] 

[INFO] --- jrebel-maven-plugin:1.1.5:generate (generate-rebel-xml) @ PROJECT ---

[INFO] Processing PROJECT with packaging jar

[INFO] 

[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ PROJECT ---

[INFO] Changes detected - recompiling the module!

[INFO] Compiling 77 source files to ... 


[INFO] --- jacoco-maven-plugin:0.7.6.201602180812:instrument (offline-instrument) @ PROJECT ---

[INFO] 

[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ PROJECT ---

[INFO] Using 'utf-8' encoding to copy filtered resources.

[INFO] Copying 3 resources

[INFO] 

[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ PROJECT ---

[INFO] Nothing to compile - all classes are up to date

[INFO] 

[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ PROJECT ---

[INFO] Skipping execution of surefire because it has already been run for this configuration

[INFO] 

[INFO] <<< maven-surefire-report-plugin:2.19.1:report < [surefire]test @ PROJECT <<<


So, surefire-reports reruns surefire:test with all the preparation steps. Whereas surefire:test detects that it was already ran, jacoco:instrument does realize that it was already executed. And as the post-processing steps do not get executed, restore-instrumented-classes is not invoked a second time. Therefore - after the surefire-report to surefire call - the classes contain instrumentation data, which then tricks the jacoco report generation that the Maven Site Plugin performs. I moved the restore-instrumented-classes invocation from its default phase to the test phase and this solved the problem. But I assume that this won't work for users that also use the Failsafe plugins together with Surefire. So, a real solution IMHO can only be that the jacoco:instrument implementation detects that it was already executed once, similar to what surefire:test does.


Florian


--
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/juY3yFMTkVw/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/CAK8jvqxJSdvP0RtuzQiPschUSuMOxqZ-W48CCtYGw8yWJHUEyQ%40mail.gmail.com.

Florian Wiesner

unread,
Apr 20, 2016, 6:02:00 AM4/20/16
to jac...@googlegroups.com
Sorry - typo correction ...

Instead of
Whereas surefire:test detects that it was already ran, jacoco:instrument does realize that it was already executed

it should have been
Whereas surefire:test detects that it was already ran, jacoco:instrument does not realize that it was already executed

Florian Wiesner

unread,
Apr 20, 2016, 6:20:40 AM4/20/16
to jac...@googlegroups.com
there is btw. another drawback of the workaround: it breaks surefire's capability to detect that it was already running the tests. So, binding restore-instrumented-classes to the test phase, leads to the tests running twice.

Mirko Friedenhagen

unread,
Apr 20, 2016, 1:39:52 PM4/20/16
to jac...@googlegroups.com

Hello Florian,

this somewhat by Design. Maven has life cycles which are structured into a sequence of phases where each phase executes plugin goals attach to the phase. When executing mvn clean deploy site you are invoking the clean phase of the clean life cycle, the deploy phase of the default life cycle and the site phase of the site life cycle. Each life cycle is independent on purpose.

For your usecase you may reconfigure surefire-report to use the report-only goal https://maven.apache.org/surefire/maven-surefire-report-plugin/report-only-mojo.html which relies upon existing test-results.

Regards
Mirko
--
Sent from my mobile

er.yogesh...@gmail.com

unread,
Dec 28, 2016, 2:45:41 AM12/28/16
to JaCoCo and EclEmma Users, fwie...@gmail.com
Did the trick worked? i am also using aspectj compile time weaving and jacoco offline instrumentation.
Can you share your pom.xml ?
also we have multiple modules and using aspectj in one module only, so i want to use on-the-fly and offline instrumentation both.
On-the-fly for non aspectj module and offline instrumentation for aspectj.
Is it possible?

I need that for unit and integration tests both. Any help would be really helpful?

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages