[JAVA] Launch SonarQube from Gradle

Introduction

I was thinking of using a static analysis tool to get my source reviewed. I estimated that it would take time to introduce it, so I tried to challenge it on the last day of the New Year holidays, so I will summarize it.

Change log

date Contents
2017.01.03 First edition
2018.02.27 Reinstalled due to OS replacement

Operating environment

~~ As of January 03, 2017, it was executed in the following environment ~~ Executed in the following environment as of 2018/02/27 ・ MacOs Sierra-> High Sierra ・ Cake Brew ・ Gradle 3.2.1-> 4.5.1 ・ SonarQube 6.1-> 7.0 ・ MySql 5.7.16 → 5.7.17 ・ IntelliJ IDEA

Reference site

Static analysis of PHP code with SonarQube Start quality control of programs with SonarQube (installation)

Introduction

  1. Download SonarQube 7.0 from CakeBrew
  2. Launch MySql and create a user and database
  3. Modify SonarQube config file
  4. Install SonarQube plugin in build.gradle
  5. Launch SonarQube
  6. Run SonarQube over Gradle from IntelliJ IDEA

MySql

Start MySql from the terminal and log in to the database. After logging in, create a user and database.

command


CREATE DATABASE sonar;
CREATE USER 'sonar'@'localhost' IDENTIFIED by 'sonar';
GRANT ALL PRIVILEGES ON sonar.* TO 'sonar'@'localhost';
FLUSH PRIVILEGES;

SonarQube configuration file

I want to follow the file through Finder, so enter the following command in the terminal

command


open -a Finder /usr/local/Cellar/sonarqube/

lang:/usr/local/Cellar/sonarqube/7.0/libexec/conf/sonar.properties


Enable and modify the following settings.
sonar.jdbc.username
sonar.jdbc.password
sonar.jdbc.url

build.gradle

build.gradle


plugins {
    id "org.sonarqube" version "2.6.2"
}

sonarqube {
    properties {
        property "sonar.host.url", "http://localhost:9000/"
        property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
        property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/test.exec"
    }
}

Launch of SonarQube

command


sonar start

You can access it at [http: // localhost: 9000](http: // localhost: 9000)

User login

Initial user & path is admin / admin

IntelliJ IDEA → Gradle → SonarQube

Double-click sonarqube from the Gradle tool in IntelliJ IDEA

スクリーンショット 2017-01-04 21.52.16.png

Customize SonarQube

SonarQube 6.1 can now parse C, Java, javascript by default. → You can analyze other languages by installing a plug-in.

The following plug-ins have been added

Plugin name
CSS / Less
Checkstyle
Findbugs
Groovy
JSON
Japanese Pack
Java Properties
Web
XML

The installation method is login with administrator privileges (admin, admin by default) Install the plugin in the Update Center from the system settings and restart SonarQube

What I had a hard time

When I raised MySql to 5.7.17, I fell into a situation where MySql did not start up obediently. Even now, we are launching by taking unnecessary steps. What should I do? .. ..

Recommended Posts

Launch SonarQube from Gradle
Launch Gradle from Ant
Using Docker from Java Gradle
Gradle