Include Code Quality for Bamboo
Breadcrumbs

Gradle

Configuration

  1. Configure the Gradle project to use the Sonar™Scanner as described in the SonarQube™ Wiki.

    1. See the official Sonar™Scanner Gradle example projects for inspiration

  2. Add a Sonar™ Scanner task to your Bamboo job:

:light_bulb_on:

Project key in Gradle

  • Specify a project key in your build.gradle file in order to have a fixed project key which is necessary for SonarQube™-based code reviews.

    XML
    sonarqube {
        properties {
            property 'sonar.projectKey', 'com.company.team:project'
        }
    }
    
  • If you are using SonarQube™ Community Edition, you need to specify the Project key again on the Bamboo Task:

    • Enable Override SonarQube properties from build

    • Set the project key:

      image-20240906-150756.png


:light_bulb_on:

To get test coverage in SonarQube™, please follow the instructions in the SonarQube™ Wiki.

Tips & Troubleshooting

If you use Sonar™ Gradle task on a remote agent, set the Gradle capability by

  • adding a Gradle 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.gradle.Gradle=path/to/your/gradle/home
    

The 'Gradle' 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)