Skip to main content

SonarQube server set up using docker in 10 minutes

Prerequisite    Install docker

Go to terminal on Mac and follow below steps
  1. docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube
  2. The above command downloads sonarqube image and uses h2 database.
  3. The sonarcube can be accessed at http://localhost:9000/about
  4. By default you can login as admin with password admin, see authentication.
  5. The moment you login you will given a screen to generate the token as below


GenerateToken





TokenGenerated



Steps to integrate your local build to push reports to sonar.

  1. Add dependencies as - classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5"
  2. Add the plugin as - apply plugin: 'org.sonarqube'
  3. Add properties in gradle.properties - 
      1. systemProp.sonar.host.url=http://localhost:9000
        systemProp.sonar.login=Token generated in step 5,6
        
        
        
        
         

  4. Command to push reports to sonar qube server 
    gradle sonarqube -Dsonar.host.url=http://sonar.mycompany.com -Dsonar.verbose=true ( we can skip -D params as they have been put in gradle.properties)


Integration of Jacoco and gradle 
1. apply plugin: "jacoco"
2. Add below to build.gradle , 
jacocoTestReport {
    group = "Reporting" reports {
        xml.enabled true csv.enabled false html.destination "${buildDir}/reports/coverage" }
}
3. Run from command line ,   
gradle test jacocoTestReport

References 


Comments