• Sonarqube+sonar scanner 扫描代码(C#,Java)


    • 环境要求:windows 10,SonarQube 6.6,JDK 1.8,MySQL 5.7,sonar-scanner 3.3
    • SonarQube下载页面:https://www.sonarqube.org/downloads/
    • SonarQube中文文档https://legacy.gitbook.com/book/revolyw/sonarqube/details
    • SonarQube:能够提供对代码的一整套检查扫描和分析功能,拥有一套服务器端程序,然后再通过客户端或者别的软件的插件的形式完成对各开发环境和软件的支持
    • 注意:对于扫描C#代码,SonarQube 7.1和SonarQube 7.7没有成功,所以降低版本下载SonarQube 6.6
    • 运行SonarQube 6.6:下载SonarQube 6.6之后,到解压目录下的binwindows-x86-64目录中,双击StartSonar.bat,就能启动SonarQube;打开浏览器,输入http://localhost:9000,如果能够进入界面则证明安装成功
    • 安装数据库MySQL 2.7:对于SonarQube对数据库MySQL的版本支持为 >=5.6 && <8.0,对于其他数据库的版本支持可查看sonarqube-6.6confsonar.properties文件;并创建数据库sonar
    • 进行sonarqube配置:sonarqube-6.6confsonar.properties文件
    1 sonar.jdbc.username=root      # 数据库用户名
    2 sonar.jdbc.password=123456    # 数据库密码
    3 # 数据库连接地址
    4 sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
    5 sonar.sorceEncoding=UTF-8     # 设置编码格式为UTF-8
    6 sonar.login=admin             # sonarqube的登录名
    7 sonar.password=admin          # sonarqube的密码
    8 sonar.web.host=0.0.0.0        # 
    9 sonar.web.port=9100           # 修改snoar端口,默认为9000
    1 Key=ce532a92558fa41465ea97dbb5f1a42673d9b67e
    • cmd测试:输入sonar-scanner -v,测试环境变量是否配置正确
    • 修改配置文件:sonar-scanner-3.3.0.1492-windowsconfsonar-scanner.properties
    1 sonar.host.url=http://localhost:9000    # sonarqube服务地址
    2 sonar.jdbc.username=root                # 数据库用户名
    3 sonar.jdbc.password=123456              # 数据库密码
    4 # 数据库连接地址
    5 sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
    6 sonar.sorceEncoding=UTF-8               # 设置编码格式为UTF-8
    7 sonar.login=admin                       # sonarqube的登录名
    8 sonar.password=admin                    # sonarqube的密码
    • 配置sonar-project.properties文件:进入C#项目的根目录,新建sonar-project.properties文件
     1 # must be unique in a given SonarQube instance
     2 sonar.projectKey=CS-project
     3 # this is the name displayed in the SonarQube UI
     4 sonar.projectName=CS-project
     5 # 自定义版本号
     6 sonar.projectVersion=1.0.0.0
     7  
     8 # Path is relative to the sonar-project.properties file. Replace "" by "/" on Windows.
     9 # Since SonarQube 4.2, this property is optional if sonar.modules is set. 
    10 # If not set, SonarQube starts looking for source code from the directory containing 
    11 # the sonar-project.properties file.
    12 sonar.sources=.
    13 
    14 # Encoding of the source code. Default is default system encoding
    15 sonar.sourceEncoding=UTF-8
    16 # C# => "cs"
    17 # CSS => "css"
    18 # SCSS => "scss"
    19 # Less => "less"
    20 # Java => "java"
    21 # Web => "web"
    22 # XML => "xml"
    23 # JSON => "json"
    24 # JavaScript => "js"
    25 sonar.language=cs
     
     
  • 相关阅读:
    聊聊WS-Federation
    用双十一的故事串起碎片的网络协议(上)
    责任链模式的使用-Netty ChannelPipeline和Mina IoFilterChain分析
    最小化局部边际的合并聚类算法(中篇)
    最小化局部边际的合并聚类算法(上篇)
    UVaLive 7371 Triangle (水题,判矩形)
    UVaLive 7372 Excellence (水题,贪心)
    POJ 3312 Mahershalalhashbaz, Nebuchadnezzar, and Billy Bob Benjamin Go to the Regionals (水题,贪心)
    UVa 1252 Twenty Questions (状压DP+记忆化搜索)
    UVa 10817 Headmaster's Headache (状压DP+记忆化搜索)
  • 原文地址:https://www.cnblogs.com/My-Sun-Shine/p/13547896.html
Copyright © 2020-2023  润新知