Sonar安装配置

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

 

解压压缩包,进行配置:

 

修改sonarqube-6.2\conf\sonar.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驱动拷贝到extensions\jdbc-driver\mysql目录下

 

修改sonarqube-6.2\conf\wrapper.conf

指定JDK路径下的java即可  

wrapper.java.command=C:\Program Files\Java\jdk1.8.0_77/bin/java

 

启动Sonar

sonarqube-6.2\bin\windows-x86-64\StartSonar.bat

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

http://127.0.0.1:9000/sonar/about

 

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

 

配置maven的环境变量

配置settings.xml文件:C:\Users\fanmingming\.m2\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://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上查看结果
posted @ 2018-02-01 16:50  庞国明  阅读(482)  评论(0编辑  收藏  举报