# Installation and Usage

## Prerequisites

To use the Diffblue SonarQube Plugin, you will need:

* A Java project that contains tests written by Diffblue Cover
* Diffblue Cover CLI
* A SonarQube Server or SonarQube Community Edition instance
* Java 17+ installed where you run SonarQube analysis

## Installation

### Download

Diffblue SonarQube Plugin releases are published on GitHub: <https://github.com/diffblue/diffblue-sonar-plugin/releases>. Download the `diffblue-sonar-plugin-X.X.X.jar` file.

### Install

The Diffblue SonarQube Plugin can be installed on SonarQube Server or SonarQube Community Edition by following the instructions provided by SonarQube:&#x20;

<https://docs.sonarsource.com/sonarqube-server/server-installation/plugins/install-a-plugin>&#x20;

<https://docs.sonarsource.com/sonarqube-community-build/server-installation/plugins/install-a-plugin>&#x20;

Third-party plugins cannot be installed on SonarQube Cloud.

## Configuration

The Diffblue SonarQube Plugin is configurable per project. It is disabled by default.

For each project that should calculate Diffblue metrics:

1. Open the project in the SonarQube UI.
2. Navigate to **Project Settings** **>** **General Settings**.
3. Go to the **Diffblue** section.
4. Toggle the plugin on or off for this project. Save your changes and they will take effect on the next run.

## Usage Patterns

The plugin will calculate and store Diffblue metrics for each module in a project if:

1. The Diffblue plugin is enabled for that project;
2. The module contains Java source code; and
3. The required JaCoCo XML input files are present.

Therefore, when SonarQube analysis runs, the required JaCoCo XML input files (`.diffblue/reports/diffblue-tests-jacoco-report.xml` and `.diffblue/reports/manual-tests-jacoco-report.xml`, which are produced by Diffblue Cover’s `dcover coverage-reports` command) need to be available to be processed. This can be done in several ways to match your preferences and the way you use Cover to generate tests.

### Option 1 – Local Test Generation

Developers generate Diffblue tests locally and commit them to the repository. CI pipelines then run `dcover coverage-reports` to generate the coverage data files before SonarQube analysis occurs. No JaCoCo XML files need to be committed to the repository.

### Option 2 – Commit Reports

Teams generate Diffblue tests and run `dcover coverage-reports` locally, committing the tests as well as both of the Diffblue-generated JaCoCo report files to the repository. When SonarQube analysis runs in CI, the required input files are present in the repository and are processed by the Diffblue SonarQube plugin.

### Option 3 – Fully in CI

The CI pipeline runs both `dcover create` and `dcover coverage-reports` to create Diffblue tests and measure coverage of Diffblue and manual tests. These steps need to occur in the pipeline prior to SonarQube analysis so that the JaCoCo XML files are present when the Diffblue SonarQube Plugin runs. The JaCoCo XML files do not need to be committed to the repository.


---

# 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/diffblue-sonarqube-plugin/installation-and-usage.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.
