5

My code structure is as follows :

events
messages
other-code
functional-tests

In the build script for jacoco, first it has to copy all classes and use that class directory to run the tool on. Can you please describe the steps wrt the target directories here. I mean how do I mention the directory on which to run the code coverage upon.

Upon build, each folder has its own target folder with classes in side them.

Here are the steps:

  1. Build project as a job in Jenkins
  2. Deploy it to user-stage
  3. Run jacoco report job in Jenkins

Jacoco report job explanation:

  1. Build step - maven 3.3.3 goals - clean test and testsuite, user-stage details and other info are passed.

  2. Post steps - execute shell

    Unable to format and paste here, so uploaded here: https://zerobin.net/?8a988cd05bf3d752#fbzMlW1b7uzD+HZnmwnd9WjQYBI3j95Q7DCIx6q+l0U=

  3. Invoke top level maven targets - maven 3.3.3 -f jacoco_pom.xml jacoco:dump antrun:run@report

The clasDir variable that's been used in the shell paste should have classes. So far, I have done this in the start of shell script.

mkdir -p target/classes
cp -R messages/target/classes target/classes

and set clsDir = target/classes,

This way I got the report on that module. My testsuite contained only one class. I want to include other modules also like events, other-code and also link the sources.

I need help on how should i set it up. The main purpose is to generate code coverage reports of functional tests.

EDIT:

Answer: Below answer helped, but it was all to be done with shell commands not any UI. So, cloning the repo, doing mvn clean package -DskipTests and copying over all first level subfolders from all the module folders helped, but then it showed error in coverage Execution data mismatch for class files. Which means that the class instrumented and the class we are using for coverage are built separately by different JVM (one in Jenkins another one thats deployed in stage).

So the solution was to not clone and recompile them, but download the manifest from the deployment repository and unpacking all the jars. This way I had all the classes in same version.

2
  • You refer to some "build script", but IMO unclear what this means - there are many various build tools and there are tons of the ways to execute JaCoCo depending on a build tool - Maven Plugin, Ant Tasks, etc. So could you please clarify your question, preferably with a more clean example - see stackoverflow.com/help/mcve ? Commented Feb 16, 2017 at 9:07
  • please check now. Commented Feb 16, 2017 at 9:42

1 Answer 1

6

To include multiple class directories by changing the Jenkins JaCoCo plugin configuration, you would need to modify the 'Path to class directories' field.

For instance, if you want to include any classes under the directories 'events' and 'other-code', you would add the following to the 'Path to class directories' section:

**/events,**/other-code

Keep in mind that if you want to add multiple directories, you have to separate each one by a comma and there can be no spaces (due to a bug with the plugin). Note: this comma bug is true of all text fields in this plugin configuration.

Here is my working JaCoCo plugin configuration: Example JaCoCo Plugin Configuration

EDIT: As mentioned in comments, one solution to this problem is to utilize whatever build tool you are dealing with (Ant, Maven, Gradle) to drop the target (ie: jar, war, etc.) into a common directory and just point the jacoco plugin there.

Sign up to request clarification or add additional context in comments.

2 Comments

It helped in a way. Thanks for hint. What I did was run the mvn goal for clean build, then copy the target of each module into a common directory called classes, that way all the classes were in a common location that could be referred by jacoco while analyzing the coverage.
If you are using pipelines and Jenkinsfile see: stackoverflow.com/a/48685604/1279002

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.