# Java project config (JaCoCo)

JaCoCo reports are an essential component of Cover Reports. Some projects have access to a version of JaCoCo that Cover can use, either through their original configuration or via Cover itself (using Maven). However, if Cover cannot find a suitable JaCoCo configuration (typically detected during [Preflight checks](/features/cover-cli/project-configuration/preflight.md)), the following minor configuration update for your projects to add the appropriate dependencies and plugins (if you're not already using JaCoCo) should be sufficient.

{% tabs %}
{% tab title="Maven" %}
Add the following declarations to the `pom.xml` file for the project. The dependency ensures that JaCoCo is available for Cover to use for coverage and reporting analysis. The plugin below configures the JaCoCo plugin to provide reporting information when running tests on the project.

```xml
<dependency>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.7</version>
</dependency>
```

```xml
<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.7</version>
  <executions>
    <execution>
      <goals>
        <goal>prepare-agent</goal>
      </goals>
    </execution>
    <execution>
      <id>report</id>
      <phase>test</phase>
      <goals>
        <goal>report</goal>
      </goals>
    </execution>
  </executions>
</plugin>
```

{% endtab %}

{% tab title="Gradle (GROOVY)" %}

1. Add the JaCoCo plugin to your build script (`build.gradle` or `build.gradle.kts`):

```
apply plugin: 'jacoco'
```

2. Include the following configuration to enable the generation of the XML reports:

```
jacocoTestReport {
   dependsOn test
   reports {
       xml.required = true
       csv.required = true
   }
}
```

3. To ensure that you run JaCoCo, we recommend adding `finalizedBy jacocoTestReport` to your test configuration, for example:

```
test {
    finalizedBy jacocoTestReport
}
```

{% endtab %}

{% tab title="Gradle (KOTLIN)" %}

1. Add the JaCoCo plugin to your build script (`build.gradle` or `build.gradle.kts`):

```
plugins {
  jacoco
}
```

2. Include the following configuration to enable the generation of the XML reports:

```
tasks {
  jacocoTestReport {
    dependsOn(test)
    reports {
      xml.required.set(true)
      csv.required.set(true)
    }
  }
}
```

3. To ensure that you run JaCoCo, we recommend adding `finalizedBy jacocoTestReport` to your test configuration, for example:

```
test {
    finalizedBy jacocoTestReport
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cover-docs-preview.diffblue.com/features/cover-reports/cover-reports-contributor/java-project-config.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
