title: “IllegalStateException: Incompatible execution data for class in…” exception from Jacoco when run for an existing ear
body: <p>I’m trying to test a legacy big fat EAR (app.ear) application using Arquillian and TestNG. To run the test I have added the testable war file (test.war) in to the existing app.ear and deployed on WildFly 10 server remotely.</p>
  
  <pre><code>@Deployment
  public static EnterpriseArchive createDeployment(){
      return ShrinkWrap.createFromZipFile(EnterpriseArchive.class, new File("../earapp/target/earapp-0.0.1-SNAPSHOT.ear"))
              .addAsModule(Testable.archiveToTest(ShrinkWrap.create(WebArchive.class, "test.war")
                      .addClass(CurrencyConverterTest.class)
                      .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")));
  }
  </code></pre>
  
  <p>The next part of my requirement is to get code coverage report after the tests are run. For that I’m using Jacoco and running it with Jacoco Maven Plugin.</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
      &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;0.7.7.201606060606&lt;/version&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;default-prepare-agent&lt;/id&gt;
              &lt;goals&gt;
                  &lt;goal&gt;prepare-agent&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
          &lt;execution&gt;
              &lt;id&gt;default-report&lt;/id&gt;
              &lt;goals&gt;
                  &lt;goal&gt;report&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>The app.ear gets deployed and the even the tests are running fine but when it comes to generate the report the Jacoco is failing with and exception <strong><em>“IllegalStateException: Incompatible execution data for class in Jacoco ………”</em></strong>  </p>
  
  <p>The exception is coming only for the class which contains the test cases. If I exclude that class (<em>CurrencyConverterTest.class</em>) using exclusion tag in Jacoco Maven Plugin the exception goes away but the reports generated by Jacoco contains no data. Also I’ve checked jacoco.exec and as far as I can say it contains valid data.</p>
  
  <p>Since I cannot share the proprietary code I’m working with, I’ve created three simple projects on github to emulate the same. </p>
  
  <ul>
  <li>Project 1 (currencycoverter): This project has one stateless ejb with a remote interface having three methods.</li>
  <li>Project 2 (<a href="https://github.com/keeshaaw/earapp" rel="nofollow noreferrer">earapp</a>): This project creates the ear file using project 1 as ejb module.</li>
  <li>Project 3 (<a href="https://github.com/keeshaaw/eartest" rel="nofollow noreferrer">eartest</a>): This project test the ear generated by project 2.</li>
  </ul>
  
  <p>To me it looks like that there is some bug in the Jacoco code but I might be wrong also. Please help me out.</p>
  
  <p><strong>Update:</strong> <strong>Steps to build the projects shared on git repo</strong></p>
  
  <p>Step 1: Check out all the three projects and import into eclipse as eclipse projects.</p>
  
  <p>Step 2: Run maven command <em>clean instll</em> for project 1 (currencyconverter)</p>
  
  <p>Step 3: Run maven command <em>clean package</em> for project 2 (earapp). This will create an ear file in the target directory.</p>
  
  <p>Step 4: Start a WildFly 10 in standalone mode on the local machine.</p>
  
  <p>Step 5: Run maven command <em>clean install</em> for project 3 (eartest). This will use the ear generated in step 3 and deploy it in WildFly 10 application server and run the tests.</p>