Sonar安装配置

时间:2022-05-03
本文章向大家介绍Sonar安装配置,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

https://www.sonarqube.org/downloads/ 下载sonar。当前版本为6.2

解压压缩包,进行配置:

修改sonarqube-6.2confsonar.properties

web配置:

sonar.web.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError -server

sonar.web.host=0.0.0.0

sonar.web.context=/sonar

sonar.web.port=9000

数据库配置(不配置使用文件数据库):

sonar.jdbc.username=root

sonar.jdbc.password=root

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

之后要将jdbc驱动拷贝到extensionsjdbc-drivermysql目录下

修改sonarqube-6.2confwrapper.conf

指定JDK路径下的java即可  

wrapper.java.command=C:Program FilesJavajdk1.8.0_77/bin/java

启动Sonar

sonarqube-6.2binwindows-x86-64StartSonar.bat

如果配置正确,访问之前配置的路径即可通过web访问管理控制台了

http://127.0.0.1:9000/sonar/about

使用命令行通过maven进行分析

配置maven的环境变量

配置settings.xml文件:C:Usersfanmingming.m2settings.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://127.0.0.1:9000/sonar
                </sonar.host.url>
            </properties>
        </profile>
     </profiles>
</settings>

在命令行下运行:

mvn clean verify sonar:sonar

或者

mvn clean install

mvn sonar:sonar

运行结束以后,到web上查看结果