Linux 安装 SonarQube 6.0 及Maven项目的使用

简介: 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/catoop/article/details/70246601 本文简单对 SonarQube 6.0 版本在Linux中的安装配置进行说明。
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/catoop/article/details/70246601

本文简单对 SonarQube 6.0 版本在Linux中的安装配置进行说明。

准备

Jdk 1.8 (略)
SonarQube 6.0 (下载:http://www.sonarqube.org/downloads/
MySQL(略)

安装

在 MySQL 中创建 Database

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; 

解压 sonarqube-6.0.zip
配置 sonarqube-6.0/conf/sonar.properties

sonar.jdbc.username=root
sonar.jdbc.password=123456
sonar.jdbc.url=jdbc:mysql://127.0.0.1:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
# 启用 sonar.web.javaOpts 并添加 -server 参数
sonar.web.javaOpts=-server -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError

配置 sonarqube-6.0/conf/sonar.properties

wrapper.java.command=/usr/local/java/jdk1.8.0_101/bin/java

配置服务

创建文件 /etc/init.d/sonar ,内容如下:

#!/bin/sh
#
# rc file for SonarQube
#
# chkconfig: 345 96 10
# description: SonarQube system (www.sonarsource.org)
#
### BEGIN INIT INFO
# Provides: sonar
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: SonarQube system (www.sonarsource.org)
# Description: SonarQube system (www.sonarsource.org)
### END INIT INFO

/usr/bin/sonar $*

依次执行如下命令(CentOS、RedHat):

ln -s $SONAR_HOME/bin/linux-x86-64/sonar.sh /usr/bin/sonar
chmod 755 /etc/init.d/sonar
chkconfig --add sonar

启动和停止服务

启动:service sonar start
停止:service sonar stop
重启:service sonar restart
注:第一次启动服务,可以查看日志 conf/sonar.log 观察进度,因为第一次会初始化数据库和相关配置需要一段时间。

访问 Sonar 添加中文插件

默认端口为 9000,默认 context 为 “/”,默认账号密码 admin/admin,如果需要修改,可以在 sonar.properties 中修改。
访问 http://127.0.0.1:9000
按如下截图操作添加中文插件:

Restart 完成后重新访问就是中文界面了

Maven 项目的使用

1、配置 maven 全局配置
在 apache-maven/conf/settings.xml 中配置如下内容:

<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://MySonarQubeServer:9000
                </sonar.host.url>
            </properties>
        </profile>
     </profiles>
</settings>

2、使用命令对代码进行分析

# 分析代码命令
mvn sonar:sonar
# 可以和打包、编译、安装等命令一起使用,例如:
mvn clean package sonar:sonar 

3、查看结果
打开 sonarqube 网页,登录进去就可以看到该项目的处理结果了。

目录
相关文章
|
3天前
|
负载均衡 Java 应用服务中间件
nginx安装在linux上
nginx安装在linux上
26 2
|
6天前
|
Linux 开发工具 C语言
Linux 安装 gcc 编译运行 C程序
Linux 安装 gcc 编译运行 C程序
27 0
|
6天前
|
Ubuntu Linux Python
Linux(15)Ubuntu安装ninja构建工具
Linux(15)Ubuntu安装ninja构建工具
16 0
|
9天前
|
NoSQL Linux 测试技术
Redis的安装(Linux版)
Redis的安装(Linux版)
158 1
|
19天前
|
缓存 Linux 测试技术
安装【银河麒麟V10】linux系统--并挂载镜像
安装【银河麒麟V10】linux系统--并挂载镜像
102 0
|
19天前
|
Linux C语言
linux yum安装ffmpeg 图文详解
linux yum安装ffmpeg 图文详解
42 0
|
19天前
|
NoSQL Linux Redis
linux 下和win下安装redis 并添加开机自启 图文详解
linux 下和win下安装redis 并添加开机自启 图文详解
17 0
|
19天前
|
Linux
linux yum 安装rar和unrar
linux yum 安装rar和unrar
60 0
|
19天前
|
Java Linux
Springboot 解决linux服务器下获取不到项目Resources下资源
Springboot 解决linux服务器下获取不到项目Resources下资源
|
17天前
|
存储 算法 Linux
【实战项目】网络编程:在Linux环境下基于opencv和socket的人脸识别系统--C++实现
【实战项目】网络编程:在Linux环境下基于opencv和socket的人脸识别系统--C++实现
40 6