Quickstart
Maven pom.xml Additions
Add this to your root pom.
<properties> <sonar.tests>src/test</sonar.tests> <sonar.sources>src/main</sonar.sources> <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin> <jacoco.version>0.8.4</jacoco.version> <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis> <sonar.language>java</sonar.language> <sonar.surefire.reportsPath>target/surefire-reports</sonar.surefire.reportsPath> <sonar.junit.reportsPath>target/surefire-reports</sonar.junit.reportsPath> <sonar.binaries>target</sonar.binaries> </properties> <build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>${jacoco.version}</version> <configuration> <destFile>${sonar.jacoco.reportsPath}</destFile> <append>true</append> </configuration> <executions> <execution> <id>agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> </executions> </plugin> </plugins> </build> <reporting> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <reportSets> <reportSet> <reports> <report>report</report> </reports> </reportSet> </reportSets> </plugin> </plugins> </reporting>
Install a sonar helm chart
see DevOps#Deploysonarviahelmchart for older Helm 2.x charts via https://github.com/helm/charts/tree/master/stable/sonarqube
Sonar Helm 3 Chart
install helm on top of your kubernetes cluster - Kubernetes Developer Guide#HelmCharts
see https://github.com/Oteemo/charts/tree/master/charts/sonarqube
biometric:wse_github michaelobrien$ helm repo add oteemocharts https://oteemo.github.io/charts "oteemocharts" has been added to your repositories biometric:wse_github michaelobrien$ helm install sonar oteemocharts/sonarqube NAME: sonar LAST DEPLOYED: Wed Apr 22 23:12:49 2020 NAMESPACE: default STATUS: deployed REVISION: 1 NOTES: 1. Get the application URL by running these commands: export POD_NAME=$(kubectl get pods --namespace default -l "app=sonarqube,release=sonar" -o jsonpath="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl port-forward $POD_NAME 8080:9000 biometric:wse_github michaelobrien$ kubectl get services --all-namespaces NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default sonar-postgresql ClusterIP 10.100.123.3 <none> 5432/TCP 51s default sonar-postgresql-headless ClusterIP None <none> 5432/TCP 51s default sonar-sonarqube ClusterIP 10.96.255.225 <none> 9000/TCP 51s biometric:wse_github michaelobrien$ kubectl get pods --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE default sonar-postgresql-0 1/1 Running 0 2m12s default sonar-sonarqube-97b94c7f7-thrw2 1/1 Running 0 2m12s $ helm list NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION sonar default 1 2020-04-23 11:59:18.6371016 -0400 EDT deployed sonarqube-6.0.1 8.2-community biometric:wse_github michaelobrien$ kubectl port-forward sonar-sonarqube-97b94c7f7-thrw2 9000:9000 Forwarding from 127.0.0.1:9000 -> 9000 Forwarding from [::1]:9000 -> 9000 http://127.0.0.1:9000/about Handling connection for 9000 To avoid [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project difference-nbi: No quality profiles have been found, you probably don't have any language plugin installed. -> [Help 1] install the java language in Administration | MarketplaceCheck the java profile in "quality profiles" after restarting the container
Install a sonar docker container
optional - use the chart instead
docker run -d --name sonarqube -p 9000:9000 sonarqube:latest
Run sonar:sonar maven target
mvn clean install -U sonar:sonar -Dsonar.host.url=http://server:9000 -Dsonar.login=your_tokenor biometric:difference-nbi michaelobrien$ mvn clean install -U sonar:sonar -Dsonar.host.url=http://127.0.0.1:9000 [INFO] --- sonar-maven-plugin:3.7.0.1746:sonar (default-cli) @ difference-nbi --- [INFO] User cache: /Users/michaelobrien/.sonar/cache [INFO] SonarQube version: 8.2.0 [INFO] Default locale: "en_CA", source code encoding: "UTF-8" [WARNING] SonarScanner will require Java 11 to run starting in SonarQube 8.x [INFO] Load global settings [INFO] Load global settings (done) | time=99ms [INFO] Server id: D3E039A1-AXGlBrNXuSaXBupyXuQc [INFO] User cache: /Users/michaelobrien/.sonar/cache [INFO] Load/download plugins [INFO] Load plugins index [INFO] Load plugins index (done) | time=36ms [INFO] Load/download plugins (done) | time=908ms [INFO] Process project properties [INFO] Process project properties (done) | time=8ms [INFO] Project key: cloud.difference:difference-nbi [INFO] Base dir: /Users/michaelobrien/wse_gitlab/difference-cloud/difference-nbi [INFO] Working dir: /Users/michaelobrien/wse_gitlab/difference-cloud/difference-nbi/target/sonar [INFO] Load project settings for component key: 'cloud.difference:difference-nbi' [INFO] Load quality profiles [INFO] Load quality profiles (done) | time=50ms [INFO] Load active rules [INFO] Load active rules (done) | time=339ms [WARNING] SCM provider autodetection failed. Please use "sonar.scm.provider" to define SCM of your project, or disable the SCM Sensor in the project settings. [INFO] Indexing files... [INFO] Project configuration: [INFO] 7 files indexed [INFO] Quality profile for java: Sonar way [INFO] ------------- Run sensors on module nbi [INFO] Load metrics repository [INFO] Load metrics repository (done) | time=39ms [INFO] Sensor JavaSquidSensor [java] [INFO] Configured Java source version (sonar.java.source): 8 [INFO] JavaClasspath initialization [INFO] JavaClasspath initialization (done) | time=10ms [INFO] JavaTestClasspath initialization [INFO] JavaTestClasspath initialization (done) | time=3ms [INFO] Java Main Files AST scan [INFO] 3 source files to be analyzed [INFO] Load project repositories [INFO] Load project repositories (done) | time=7ms [INFO] 3/3 source files have been analyzed [INFO] Java Main Files AST scan (done) | time=1046ms [INFO] Java Test Files AST scan [INFO] 1 source files to be analyzed [INFO] Java Test Files AST scan (done) | time=51ms [INFO] 1/1 source files have been analyzed [INFO] Java Generated Files AST scan [INFO] 0 source files to be analyzed [INFO] Java Generated Files AST scan (done) | time=1ms [INFO] 0/0 source files have been analyzed [INFO] Sensor JavaSquidSensor [java] (done) | time=1247ms [INFO] Sensor SurefireSensor [java] [INFO] parsing [/Users/michaelobrien/wse_gitlab/difference-cloud/difference-nbi/target/surefire-reports] [INFO] Sensor SurefireSensor [java] (done) | time=61ms [INFO] Sensor JavaXmlSensor [java] [INFO] Sensor JavaXmlSensor [java] (done) | time=0ms [INFO] ------------- Run sensors on project [INFO] Sensor Zero Coverage Sensor [INFO] Sensor Zero Coverage Sensor (done) | time=7ms [INFO] Sensor Java CPD Block Indexer [INFO] Sensor Java CPD Block Indexer (done) | time=11ms [INFO] SCM Publisher No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it. [INFO] CPD Executor 1 file had no CPD blocks [INFO] CPD Executor Calculating CPD for 2 files [INFO] CPD Executor CPD calculation finished (done) | time=5ms [INFO] Analysis report generated in 43ms, dir size=35 KB [INFO] Analysis report compressed in 22ms, zip size=11 KB [INFO] Analysis report uploaded in 302ms [INFO] ANALYSIS SUCCESSFUL, you can browse http://127.0.0.1:9000/dashboard?id=cloud.difference%3Adifference-nbi [INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report [INFO] More about the report processing at http://127.0.0.1:9000/api/ce/task?id=AXGlH_HAlJn8qUa7KQi0 [INFO] Analysis total time: 2.545 s [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11.934 s
Java Requirements
The following folders must have some minimal source
src/main/java
src/main/test