Adding a project

A project is created in SonarQube automatically on its first analysis. Before we can scan a project, we need to choose an analysis method. In this recipe, we will launch a Gradle analysis. The other available methods are listed in the See also section.

Let's perform the following steps to add a new project to SonarQube:

  1. Clone an example repository to scan:
$ git clone https://github.com/javajon/code-analysis.git
$ cd code-analysis/microservice/

  1. For this example, we also need Java 1.8 installed on our node. If you already have it, skip to step 4:
$ sudo apt install openjdk-8-jre-headless default-jdk
  1. Confirm the version of Java you're using:
$ java -version openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1~deb9u1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
  1. Get the SonarQube service's external IP:
$ export SONAR_SVC=$(kubectl get svc --namespace sonarqube sonar-sonarqube -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
  1. Run the analysis. The analysis will complete in a couple of minutes:
$ ./gradlew -Dsonar.host.url=http://$SONAR_SVC:9000 sonarqube
....
BUILD SUCCESSFUL in 13s
6 actionable tasks: 1 executed, 5 up-to-date
  1. Switch back to the SonarQube portal to see the new project:

Now, you will be able to see your new project on the SonarQube portal.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.19.174