Quality tools of the project, not of whoever uses the library: none of this reaches the main jar or its dependencies.
JaCoCo is part of the normal build: prepare-agent instruments the tests and report generates the report in the
prepare-package phase.
./mvnw verifyIt leaves in target/site/jacoco/ the HTML report (index.html) and jacoco.xml, which is the one SonarQube reads.
./mvnw -Psonar verifyThe sonar profile runs with maven-failsafe-plugin the SonarQubeAnalysisIT test
(src/test/java/io/github/eldiegos/bpmncode/quality) after compiling, testing and generating the coverage. The test:
- starts an ephemeral SonarQube with Testcontainers (image from the
sonarqube.imageproperty, by defaultsonarqube:community) and waits until/api/system/statusanswersUP; - changes the
adminpassword and creates a token; - runs
sonar-maven-pluginon the already compiled project, withtarget/site/jacoco/jacoco.xmlas coverage; - waits for the server to process the analysis and writes the report;
- if requested, keeps the server open for some minutes (see Reviewing it in the browser);
- removes the container.
Requirements: Docker running and about 2-3 GB of free memory for the container. Another image:
./mvnw -Psonar verify -Dsonarqube.image=sonarqube:<tag>In target/sonar/:
| File | Content |
|---|---|
issues.txt |
quality gate, metrics, number of issues and security hotspots, and one line per open issue (severity, type, rule, file:line, message) |
measures.json |
metrics: coverage, bugs, vulnerabilities, code smells, duplication, lines, ratings |
quality-gate.json |
quality gate status |
hotspots.json |
security hotspots |
scanner.log |
scanner output |
url.txt |
only with sonar.keepOpenMinutes > 0: URL of the project dashboard and the admin user with its password |
The first lines of issues.txt are also printed to the console.
./mvnw -Psonar verify -Dsonar.keepOpenMinutes=30The sonar.keepOpenMinutes property (from pom.xml, 0 by default: the container is closed when it finishes) keeps
SonarQube open for N minutes after writing the report. It writes to target/sonar/url.txt the dashboard URL
(http://localhost:<port>/dashboard?id=bpmncode, with the port assigned by Testcontainers) and the admin user with
the password set by the test, and prints it to the log:
SonarQube stays open for 30 min at http://localhost:<port>/dashboard?id=bpmncode (admin / <password>)
After that time the container is removed as usual; meanwhile the build waits.
It does not fail because of the issues: they are the report. It fails if the server does not start (5-minute wait), if
the scanner ends with an error (see scanner.log) or if the analysis is not processed within 5 minutes or does not end
in SUCCESS.
Analyze, fix the issues in issues.txt and analyze again. Each run starts from a new server, with no history.
Testcontainers is a test dependency (not transitive) and the io.github.eldiegos.bpmncode.quality package is
excluded from the published test jar (classifier tests). The release profile does not run the analysis (see
Publishing).