配置sonarqube+maven

本文档详细介绍了如何配置SonarQube和Maven进行代码质量管理。首先,介绍了准备步骤,包括下载SonarQube、SonarScanner、Java JDK 1.7和MySQL 5.7.10。接着,详细阐述了配置MySQL的过程,包括创建配置文件my.ini、安装MySQL服务以及启动服务。然后,讲解了启动SonarQube服务器的方法。再者,配置SonarScanner,修改其配置文件以连接MySQL。此外,还指导在项目中创建sonar-project.properties文件,并添加相关配置。最后,提到了需修改Maven的settings.xml文件,以便Maven项目能与SonarQube集成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

准备工作:去到官网下载1.sonarqube4.

                                            2.sonar-runner2.4以前,2.4之后改为sonar-scanner2.5

                                            3.java,jdk1.7

                                            4.mysql 5.7.10,免安装版

                 第一阶段,配置mysql:1.复制my-default.ini,改为my.ini

                                       复制以下内容替换掉my.ini以前内容:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
basedir = D:/sonarQube/mysql-5.7.10-win32            #mysql路径
datadir = D:/sonarQube/mysql-5.7.10-win32/data       #在mysql中创建一个data文件夹注意data前/
# port = .....
# server_id = ....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
                                                                   

                                                                2.管理员模式的cmd,输入mysql路径\bin\mysqld.exe --install安装(安装后路径里面会新建一个data文件夹),移除用 前面的路径 --remove。

                                                                3.打开mysql :   还是在cmd下输入 net start mysql。

                   第二阶段,解压sonarqube:去到bin目录下,根据操作系统选择启动服务,点击StartSonar.bat,启动sonarqube。

                   第三阶段,配置sonar-scanner:将conf下的配置文件向之前改sonarqube类似的更改,取消注释mysql,然后启动。

                   第四阶段,在项目下新建,sonar-project.properties,加上如下代码:


# required metadata

# My project------项目名称

sonar.projectKey=JAVA

sonar.projectName=JAVA

sonar.projectVersion=1.0

# path to source directories (required)

# src---------修改成你的源文件夹路径,多个路径逗号隔开

sonar.sources=F:/MyJava/JAVA

# path to test source directories (optional)

# testDir1,testDir2--------修改成你的测试文件夹路径, 如果测试可以取消注释

# tests=testDir1,testDir2

# path to project binaries (optional), for example directory of Java #bytecode

# binaries--------编译后的class目录

binaries=bin

# path to project libraries (optional)

#libraries=junit.jar

# advanced parameters# required metadata
# Language

sonar.language=java

# Encoding of the source files

sonar.sourceEncoding=UTF-8
               第五阶段,已经可以实现对java项目的管理,在项目目录下cmd,然后输入sonar-runner,成功后,代码会在sonarqube上面管理。

               第六阶段,要实行对maven项目的管理,还需要配置maven的setting.xml文件。加上如下代码,数据库还是以mysql示范:

  <!--sonar配置maven 文件项   -->
        <profile>  
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
             <properties>
                <!-- database-->
              <sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar</sonar.jdbc.url>
              <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
              <sonar.jdbc.username>sonar</sonar.jdbc.username>
              <sonar.jdbc.password>sonar</sonar.jdbc.password>
               <!-- Optional URL to server. Default value is http://localhost:9000 -->
              <sonar.host.url>http://localhost:9000</sonar.host.url>
            </properties>
        </profile>

             第七阶段,在maven项目文件下cmd输入:mvn sonar:sonar,然后大功告成



                             

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值