Wednesday, August 26, 2015

Sonarqube - How to install and get start

■ Install sonar-runner
■ Make the directory
$ mkdir ~/sonarqube
$ cd ./sonarqube
■ Download the sonarqube-5.1.2.zip
$ wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-5.1.2.zip
■ Decompress the sonarqube-5.1.2.zip
$ unzip ./sonarqube-5.1.2.zip
■ Change the folder name
$ mv ./sonarqube-5.1.2 ./sonarqube
■ Install sonar-runner
■ Download the sonar-runner-dist-2.4.zip
$ wget http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
■ Decompress the sonarqube-5.1.2.zip
$ unzip ./sonar-runner-dist-2.4.zip
■ Change the folder name
$ mv ./sonar-runner-2.4 ./sonar-runner
■ Add the following lines into the file /home/njoonk/.profile
export SONAR_RUNNER_HOME=/home/njoonk/sonarqube/sonar-runner
export PATH=$SONAR_RUNNER_HOME/bin:$PATH
■ Execute for applying
$ source ./.profile
■ Start web server
$ ${SONAR_HOME}/sonarqube/bin/macosx-universal-64/sonar.sh start

http://localhost:9000/

■ Add the following lines into build.gradle
apply plugin: 'org.sonarqube'

//./gradlew sonarqube
sonarqube {
    properties {
        property "sonar.projectName", "Java :: Utility Project :: Gradle Utility"
        property "sonar.projectKey", "$project.group:$project.name"
        property "sonar.language", "java"
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.junit.reportsPath", "${project.buildDir}/test-results"
        property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
    }
}
buildscript {
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
      classpath 'org.ajoberstar:gradle-jacoco:0.1.0'
      classpath 'org.sonarqube.gradle:gradle-sonarqube-plugin:1.0'
    }
}
■ Execute and analyze
$ gradle sonarqube
\Download https://plugins.gradle.org/m2/org/sonarqube/gradle/gradle-sonarqube-plugin/1.0/gradle-sonarqube-plugin-1.0.pom
Download https://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-api/2.4/sonar-runner-api-2.4.pom
Download https://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner/2.4/sonar-runner-2.4.pom
Download https://repo1.maven.org/maven2/com/google/guava/guava/17.0/guava-17.0.pom
Download https://repo1.maven.org/maven2/com/google/guava/guava-parent/17.0/guava-parent-17.0.pom
Download https://plugins.gradle.org/m2/org/sonarqube/gradle/gradle-sonarqube-plugin/1.0/gradle-sonarqube-plugin-1.0.jar
Download https://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-api/2.4/sonar-runner-api-2.4.jar
Download https://repo1.maven.org/maven2/com/google/guava/guava/17.0/guava-17.0.jar
:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
:processResources UP-TO-DATE
:classes
:compileTestJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7
1 warning
:processTestResources UP-TO-DATE
:testClasses
:test
:sonarqube
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Work directory: /home/njoonk/git/utility/build/sonar
INFO: SonarQube Server 5.1.2
01:11:20.009 INFO  - Load global repositories
01:11:20.213 INFO  - Load global repositories (done) | time=207ms
01:11:20.215 INFO  - Server id: 20150826001338
01:11:20.217 INFO  - User cache: /home/njoonk/.sonar/cache.
.
omission
.
01:11:30.764 INFO  - Analysis reports sent to server in 73ms
01:11:30.765 INFO  - ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard/index/io.utility:utility
01:11:30.765 INFO  - Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report.

BUILD SUCCESSFUL
■ This is a sample.
https://github.com/minziappa/utility/blob/master/build.gradle

■ Reference
http://docs.sonarqube.org/display/SONAR/Analyzing+with+Gradle
https://github.com/SonarSource/sonar-examples/zipball/master

No comments:

Post a Comment