SonarQube安装及使用(idea集成&linux安装注意事项)

1.需要安装的软件:

  a.sonarqube(6.7.3)       
   下载地址:http://www.sonarqube.org/downloads/
  b.sonar-runner(2.5)
   下载地址:https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.5.zip
  c.Mysql(5.6及以上)
  d.jdk(1.8用于集成idea)

 2.启动及配置:

  a.单独启动SonarQube路径:  sonarqube-6.7.3\bin\windows-x86-64\StartSonar.bat
      TIP:我出现过远程连接强行被关闭的问题,后版本改为6.7.3解决
  b.访问地址:http://localhost:9000
  c.创建数据库:sonar(每次检查的结果都会自动存入数据库)
  d.配置SonarQube\conf\sonar.properties文件
        sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
            &rewriteBatchedStatements=true&useConfigs=maxPerformance
	sonar.jdbc.username=用户名
	sonar.jdbc.password=密码
	sonar.sorceEncoding=UTF-8
	sonar.login=admin
	sonar.password=admin
  e.重启服务再次访问9000端口(如果出现被占用的情况,右键任务栏-文件管理器-清除所有JavaSE的进程,一般是三个)
  f.安装中文插件:配置-->应用市场-->搜索chinese pack -->install 重启生效
  	TIP:建议安装 SonarJS SonarJava SonarTS
  TIP:建议安装 SonarJS SonarJava SonarTS
  

 3.idea集成SonarQube

    a.setting --> plugins:安装插件SonarLint 重启生效

    b.setting --> SonarLint General Settings

    c.创建令牌:

    d.update binding (出现过Tyscript版本过低问题,升级SonarTS即可)

 4.运行SonarQube进行codeView

    a.单个文件检查:点击文件,代码界面右键Analyze With SonarLint

    b.多个文件检查:SonarLint tool --> Report -->文件夹图标

    c.maven命令启动,检查结果会显示在服务器中

maven-setting.xml添加:
  	<profile>
      <id>sonar</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar</sonar.jdbc.url>
        <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
        <sonar.jdbc.username>root</sonar.jdbc.username>
        <sonar.jdbc.password>832231</sonar.jdbc.password>
        <sonar.host.url>http://localhost:9000</sonar.host.url>
      </properties>
    </profile>

    pom.xml添加:
    <build>
        <plugins>
            <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>3.2</version>
            </plugin>
        </plugins>
    </build>

    运行命令:先clean install 后 sonar:sonar 服务端会显示相关代码问题

结果展示:

linux安装:

    a.建议使用sonarqube 6.5版本 ,因为sonarqube自带es ,版本大于6.5 的不支持root启动es,大于6.5可以通过创建其他用户启动es来解决这个问题

    b.其次启动linux-x86-x64下面的sonar.sh,启动命令为./sonar.sh start(stop,console,restart)

    c.如果发现提示sonarqube已启动,但是访问没有效果,查看sonar/logs下面的日志,主要是es.log sonar.log和web.log,其中必有出错原因

    d.如果出现更新中心不能访问的问题,建议自己下载中文插件包(需要对应版本号,否则无法启动),我的是6.5对应1.17版本

    e.将sonarqube设备开机自启,因为不是服务,所以选择加入启动命令,

        vim/etc/rc.local   添加 /usr/java/sonar/bin/linux-x86-64/sonar.sh start

                                                                                                                                                         end

                                                                                                                                                         22.30 

                                                                                                                                                         2018.5.15

        

猜你喜欢

转载自blog.csdn.net/u010005147/article/details/80310192