title: How to have code coverage in Jenkins with Jacoco and multiple modules?
body: <p>My code structure is as follows :</p>
  
  <blockquote>
    <p>events<br>
    messages<br>
    other-code<br>
    functional-tests</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>Upon build, each folder has its own target folder with classes in side them.</p>
  
  <p>Here are the steps:</p>
  
  <ol>
  <li>Build project as a job in Jenkins</li>
  <li>Deploy it to user-stage</li>
  <li>Run jacoco report job in Jenkins</li>
  </ol>
  
  <p>Jacoco report job explanation:</p>
  
  <ol>
  <li><p>Build step - maven 3.3.3
  goals  - clean test
  and testsuite, user-stage details and other info are passed.    </p></li>
  <li><p>Post steps - execute shell</p>
  
  <p>Unable to format and paste here, so uploaded here: <a href="https://zerobin.net/?8a988cd05bf3d752#fbzMlW1b7uzD+HZnmwnd9WjQYBI3j95Q7DCIx6q+l0U=" rel="nofollow noreferrer">https://zerobin.net/?8a988cd05bf3d752#fbzMlW1b7uzD+HZnmwnd9WjQYBI3j95Q7DCIx6q+l0U=</a> </p></li>
  <li><p>Invoke top level maven targets - maven 3.3.3
  -f jacoco_pom.xml jacoco:dump  antrun:run@report</p></li>
  </ol>
  
  <p>The <code>clasDir</code> variable that's been used in the shell paste should have classes. So far, I have done this in the start of shell script.</p>
  
  <pre><code>mkdir -p target/classes
  cp -R messages/target/classes target/classes
  </code></pre>
  
  <p>and set <code>clsDir = target/classes</code>,</p>
  
  <p>This way I got the report on that module. My testsuite contained only one class. I want to include other modules also like <code>events</code>, <code>other-code</code> and also link the sources.</p>
  
  <p>I need help on how should i set it up. The main purpose is to generate code coverage reports of functional tests.</p>
  
  <p>EDIT:</p>
  
  <p>Answer: Below answer helped, but it was all to be done with shell commands not any UI. So, cloning the repo, doing <code>mvn clean package -DskipTests</code> and copying over all first level subfolders from all the module folders helped, but then it showed error in coverage <strong>Execution data mismatch for class files</strong>. 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). </p>
  
  <p>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.</p>