Hello, I have been trying to get Jacoco to work with the maven build, because we used sonarqube to as part of our process and we need code coverage metrics. However, no matter what I do, Jacoco is always analyzing zero classes.

Is there anything we can do for this?

asked 09.01.2020 at 08:27

TareqK's gravatar image

TareqK
(suspended)
accept rate: 25%

Hi

Seems to be an maven configuration problem to me... How do you configure you're maven build? Do you use the jacoco-maven-plugin? Did the tests run? Which JUnit version? Maybe this blog post can help you: https://www.mkyong.com/maven/maven-jacoco-code-coverage-example/

Kind regards

Lukas

(09.01.2020 at 08:39) Lukas Lieb ♦♦ Lukas%20Lieb's gravatar image

I Did indeed do the maven setup, im using maven 4.12 with powermock and mockito, and all the test do run. I checked this configuration compared to the examples on baeldug and mkyong, but still no luck. Jacoco does see all the packages, its just ignoring every class in them.

(09.01.2020 at 09:01) TareqK TareqK's gravatar image

you may have to set explicitly the test releated vars in pom.xml: e.g.

<build>
    <testSourceDirectory>src_test</testSourceDirectory>
    <testOutputDirectory>target/test-classes</testOutputDirectory>
</build>

if that doesn't help: the issue is very likely that jacoco works with a javaagent. Since we setup a custom JDT compiler run, this agent may can not be made known with a standard approach.

However, we can provide detailed feedback if you share a simple project that shows the issue and file it as official support request.

(10.01.2020 at 05:22) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

Updates on this :

Got it to work, turns out as @Reguel said, the JDT compiler wont play with a javaagent. I got around this by using the offline mode of jacoco, and copying the generated classes from the classes directory in the correct target/classes and target/test-classes directories . This is what the pom section looks like :

Gist Of pom.xml parts

You also need to set the <testoutputdirectory> as well, otherwise it wont work

The reports are generated in the target/site/jacoco folder, and the jacoco.exec file is in the target folder as well

link

answered 13.01.2020 at 10:07

TareqK's gravatar image

TareqK
(suspended)
accept rate: 25%

edited 13.01.2020 at 10:08

Cool solution: thanks for sharing!

One remark though:

  • you can make the resource copy process slightly simpler by teaching ivy projects where to put compile classes into (our default /classes is not the best for maven natured projects)
  • use the package explorer > context menu > properties > java build path > source
  • set the settings outlined in the screenshot:

(13.01.2020 at 10:18) Reguel Werme... ♦♦ Reguel%20Wermelinger's gravatar image

@Reguel Thanks for the feedback, ill try it out as soon as i can!

(13.01.2020 at 10:29) TareqK TareqK's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×22
×8
×4
×2

Asked: 09.01.2020 at 08:27

Seen: 1,496 times

Last updated: 13.01.2020 at 10:29