dancing around shade plugin relocation

295 views
Skip to first unread message

Chris Burroughs

unread,
Aug 23, 2017, 4:53:30 PM8/23/17
to jac...@googlegroups.com
I am trying to use the jacoco maven plugin to report test coverage for
integration tests. There are a two related issues that complicate this:
* This is a multi module project.
* The primary code and integration tests are in separate modules. The
integration test module has no classes in src/main.
* The primary module is shaded and dependencies are relocated [1]. The
bytecode in primary-module/target/classes is normal, but in
primary-module/target/my-module.jar references to (for example) `import
com.example.Foo;` have been rewritten to `import
vendor.com.example.Foo`. The integration tests depend on the primary
module, and thus use the shaded jar with relocations (the intent was in
part to have the integration tests also verify that nothing went awry
with the shading process).
* I want coverage information for my classes, not the shaded dependencies.

I believe this is similar to other issues with modified classes. I
tried configuring jacoco for both unit and integration tests [2] and
then unpacking the modified class files [3] before running the
integration tests. When run through maven, all classes report zero
coverage for integration tests. Trying to debug what was in the exec
file if not coverage information I build the cli from master.

Running (in the integration test directory):
java -jar jacococli.jar report target/jacoco-it.exec \
--classfiles target/classes --html foo \
--sourcefiles ../java-manta-client/src/main/java/

Appears to work (in that the report displays nice green coverage
information. I can't figure out how that invocation is different from
what maven is doing. I tried running with a SNAPSHOT plugin to no avail.

Questions:
* What am I doing different in maven from the working cli invocation?
* If the above worked through maven, is there a way to override
"sourcefiles" for the maven report?
* Is there a better overall approach to this problem than this
specific hack? I had started with the report-aggregate goal, but could
not figure out a way around not coverage reported with: [WARNING]
Classes in bundle 'java-manta-client' do no match with execution data.
For report generation the same class files must be used as at runtime.


[1]
https://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html


[2]
https://github.com/cburroughs/java-manta/blob/inter-cov/pom.xml#L443-L492


[3]
https://github.com/cburroughs/java-manta/blob/inter-cov/java-manta-it/pom.xml#L117-L154

Chris Burroughs

unread,
Aug 25, 2017, 5:20:49 PM8/25/17
to jac...@googlegroups.com
With this change to what I had previously:

<id>integration-test-report</id>
<phase>integration-test</phase>
<goals>
- <goal>report</goal>
+ <goal>report-integration</goal>
</goals>

I get what appear to be correct integration test reports. While that
semantically makes sense, I don't see what difference between ReportMojo
and ReportITMojo would cause only one to work in this case.

While I have a report on classes with this approach, the report is still
reasonably lacking lacking "sourcefiles". I see a way to specify the
source *encoding* per goal, but how can I specify the source file
*location*?

Mirko Friedenhagen

unread,
Aug 26, 2017, 3:27:24 AM8/26/17
to jac...@googlegroups.com
Hello,

the difference between the two mojos is mainly in paths to the exec file holding the coverage information (target/jacoco resp. target/jacoco-it) and the directory with the generated report (target/site/jacoco resp. target/site/jacoco-it)

prepare-agent writes to jacoco.exec, prepare-agent-integration to jacoco-it.exec and the reporting goals pick up stuff from the appropriate file. 

Concerning source files ths plugin just uses the standard Maven location, e.g. src/main/java as specified in the pom, see e.g. https://maven.apache.org/guides/mini/guide-using-one-source-directory.html

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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/dd5721db-e47d-0564-9ae6-104740d0ef74%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages