Configuration
Configure the Maven project to use the Sonar™Scanner as shown in the SonarQube™ Wiki.
See the official Maven example for inspiration
-
Ensure the
pom.xmlof your project contains thesonar-maven-pluginas dependencyXML<build> <pluginManagement> <plugins> <plugin> <groupId>org.sonarsource.scanner.maven</groupId> <artifactId>sonar-maven-plugin</artifactId> <version>3.7.0.1746</version> </plugin> </plugins> </pluginManagement> </build> -
[optional: code coverage] ensure your
pom.xmlintegrates the Jacoco plugin, see https://docs.sonarqube.org/latest/analysis/test-coverage/java-test-coverage/ for more details.
[optional: code coverage] Add a Maven task to your Bamboo job:
Run the tests and generate code coverage reports:
clean org.jacoco:jacoco-maven-plugin:prepare-agent verify
Add a Sonar™Scanner for Maven task to your Bamboo job:
Tips & Troubleshooting
If you use Sonar™Scanner Maven task on a remote agent, set the Maven capability by
-
adding a Maven capability to your remote agent in the Bamboo UI
-
or add the following key/value pair to your
bamboo-agent-home/bin/bamboo-capabilities.propertiesfile, see Bamboo docs for more details:system.builder.mvn3.Maven3=path/to/your/maven3/home
The 'Maven3' part is the executable label.
SonarQube™ scanners need access to the full git repository. If you encounter issues, e.g. in a containerized build, ensure that you
-
uncheck "Use shallow clones" option (Fetches the shallowest commit history possible. Do not use if your build depends on full repository history)
-
check "Fetch whole repository" option (Fetches whole repository instead of only one branch)