Include Code Quality for Bamboo
Breadcrumbs

Maven

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.xml of your project contains the sonar-maven-plugin as dependency

    XML
    <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.xml integrates 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:

Bash
clean org.jacoco:jacoco-maven-plugin:prepare-agent verify
image-20220718-140532.png

Add a Sonar™Scanner for Maven task to your Bamboo job:

image-20240906-150453.png

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.properties file, 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)