LoginSignup
2
3

More than 5 years have passed since last update.

Mac にSonarQubeをインストールしてソース解析に挑戦

Last updated at Posted at 2018-08-20

SonarQubeインストール手順

  • brewで簡単インストール
$ brew install sonarqube
  • mavenもbrewでインストール。ということで、Javaが今回の解析対象のソースです
$ brew install maven
  • 私の端末では postgreが既にインストールされていたので、アカウントとスキマーを作成

    • アカウント名:sonar
    • パスワード:sonar
    • スキーマ:sonar
  • SonarQubeの設定

#
# sonar.properties 場所
#
$ pwd
/usr/local/Cellar/sonarqube/7.3/libexec/conf

#
# sonar.properties の設定内容
#
$ cat sonar.properties | grep -v "^#" | grep -v "^$"
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonar
sonar.web.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
sonar.web.host=127.0.0.1
sonar.web.context=/sonar
sonar.web.port=9000
sonar.path.data=/usr/local/Cellar/sonarqube/7.3/libexec/data
sonar.path.temp=/usr/local/Cellar/sonarqube/7.3/libexec/temp
  • SonarQube起動
$ sonar start
  • ブラウザでSonarQubeにアクセス
http://localhost:9000/sonar

以前、セットアップがうまく行かず投げ出していたので、今回7.2から7.3にアップグレードしていました。そうすると、ブラウザにDBの内容も古いよ、バージョンアップしなさいというメッセージが表示されました。
これまた、方法が分からず困っていたのですが、ログを見たらヒントがログに出力されていました。
その支持通り /setup にアクセスしたらうまくトップページが表示されました♪

$ pwd
/usr/local/Cellar/sonarqube/7.3/libexec/logs

$ tail sonar.log
################################################################################
      Database must be upgraded. Please backup database and browse /setup
################################################################################

http://localhost:9000/sonar/setup
  • ソース解析
#
# ソース解析対象のあるEclipseのプロジェクトのディレクトリに移動
#
cd "プロジェクトのディレクトリ"

#
# 準備のためのコマンド実行
#
$ mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true

#
# ソース解析コマンド
#
$ mvn sonar:sonar

「mvn sonar:sonar」コマンドでエラーが発生。デバッグモードで実行したら、パスが違う為に失敗していることが判明。(/sonar がついていない)

$ mvn sonar:sonar -X
ERROR: Sonar server 'http://localhost:9000' can not be reached

mavenのsetting.xml に以下を追加してコマンド再実行したら BUILD SUCCESS !!!

<settings>
    <pluginGroups>
        <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups>
    <profiles>
        <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- Optional URL to server. Default value is http://localhost:9000 -->
                <sonar.host.url>
                  http://localhost:9000/sonar
                </sonar.host.url>
            </properties>
        </profile>
     </profiles>
</settings>
  • ブラウザで解析結果を確認できました。ちなみに、ログインIDとパスは、adminでした。

References

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3