Skip to main content
查利博客

Install SonarQube on Mac

After we finished coding our fantastic project, this not the end of the story. We still need some extra works like testing such as penetration test, vulnerability test or loading test and code reviews to ensure our code quality. In this article, I will show you how to do a code review by using the open-source platform called SonarQube and it is completely free!

Install SonarQube on Mac #

First, you can download the SonarQube from here and unzip it. Next, go to the bin directory for example .../sonarqube-9.1.0.47736/bin/macosx-universal-64 and run the sonar.sh script by typing this command ./sonar.sh console . Wait for the SonarQube server to start and allow Mac to install SonarQube (Mac always reject apps downloaded from unknown site). This can be done in Security & Privacy settings. If the server is up, you can access SonarQube from localhost:9000. The default username and password are admin / admin.

Analysis a Spring Boot Project #

To analysis a Spring Boot based project, simply add the following dependencies in the pom.xml file.

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.sonarsource.scanner.maven</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>3.4.0.905</version>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

Next, navagate to your root project directory and type the following command:

mvn sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login=token-please-replace-me

Note that you need to generate the token first. Go to My Account, select Security and create your token.

Possible Error and Solution #

After SonarQube successfully scanned our project, some errors could happen and somehow we cannot check the results of code analysis correctly, it happened to me. Don't worry, you can go to the .../sonarqube-9.1.0.47736/logs directory and check the es.log and web.log. If you found that the error is related to the Elasticsearch like Caused by: org.elasticsearch.ElasticsearchException: Elasticsearch exception . It could be the index does not created correctly. The solution is simple, just go the .../sonarqube-9.1.0.47736/data directory and delete the es7 folder (it could be es6 or something similar). Restart the server and enjoy!