博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Sonar学习的记录
阅读量:6986 次
发布时间:2019-06-27

本文共 3663 字,大约阅读时间需要 12 分钟。

hot3.png

1. >> 安装

1. 从下载最新版本.(本文使用的是3.1.1)

2. 解压下载包, 进入解压文件的bin目录下, 会有对应不同系统的多个版本. 如下图: 

(本文使用的是linux-x86-64版本)

3. 将bin/linux-x86-64目录配置到LINUX的PATH的系统变量里.

4. 使用sonar.sh start即可启动(通过解压后文件的logs目录可以看到启动的情况).启动成功后访问. 默认使用的数据库为derby. 

5. 将数据库改为MYSQL. 通过修改解压文件的conf目录下的sonar.properties配置. 将

        sonar.jdbc.url

        sonar.jdbc.driverClassName

        sonar.jdbc.validationQuery

        sonar.jdbc.username

        sonar.jdbc.password

    的注释打开并配置. 参考配置如下:

#----- Credentials# Permissions to create tables and indexes must be granted to JDBC user.# The schema must be created first.sonar.jdbc.username: rootsonar.jdbc.password: coke#----- Embedded database Derby# Note : it does not accept connections from remote hosts, so the# sonar server and the maven plugin must be executed on the same host.# Comment the following line to deactivate the default embedded database.#sonar.jdbc.url:                            jdbc:derby://localhost:1527/sonar;create=true#sonar.jdbc.driverClassName:                org.apache.derby.jdbc.ClientDriver#sonar.jdbc.validationQuery:                values(1)# directory containing Derby database files. By default it's the /data directory in the sonar installation.#sonar.embeddedDatabase.dataDir:# derby embedded database server listening port, defaults to 1527#sonar.derby.drda.portNumber:               1527# uncomment to accept connections from remote hosts. Ba default it only accepts localhost connections.#sonar.derby.drda.host: 0.0.0.0#----- MySQL 5.x/6.x# Comment the embedded database and uncomment the following line to use MySQLsonar.jdbc.url:                            jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true# Optional propertiessonar.jdbc.driverClassName:                com.mysql.jdbc.Driversonar.jdbc.validationQuery:                select 1

    另外, 对应的数据库需要自己创建, 否则会启动sonar失败.

ps: 学习参考自: 

2. >> 使用Sonar Runner分析项目

1. 从下载最新版本.(本文使用的是1.4)

2. 解压后进入conf目录, 修改sonar-runner.properties配置文件(本例使用mysql). 将

        sonar.jdbc.url

        sonar.jdbc.driver

        sonar.jdbc.username

        sonar.jdbc.password

    的注释打开并配置. 参考配置如下:

#----- Default Sonar server#sonar.host.url=http://localhost:9000#----- PostgreSQL#sonar.jdbc.url=jdbc:postgresql://localhost/sonar#sonar.jdbc.driver=org.postgresql.Driver#----- MySQLsonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8sonar.jdbc.driver=com.mysql.jdbc.Driver#----- Oracle#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE#sonar.jdbc.driver=oracle.jdbc.driver.OracleDriver#----- Global database settingssonar.jdbc.username=rootsonar.jdbc.password=coke#----- Default directory layout#sources=src/main/java#tests=src/test/java#binaries=target/classessonar.sourceEncoding=UTF-8

3. 
将bin目录配置到LINUX的PATH的系统变量里.

4.  在项目的根路径创建名为 sonar-project.properties 的文件. 文件内容格式如下:

# required metadatasonar.projectKey=my:projectsonar.projectName=My projectsonar.projectVersion=1.0 # path to source directories (required)sources=srcDir1,srcDir2 # path to test source directories (optional)tests=testDir1,testDir2 # path to project binaries (optional), for example directory of Java bytecodebinaries=binDir # optional comma-separated list of paths to libraries. Only path to JAR file and path to directory of classes are supported.libraries=path/to/library.jar,path/to/classes/dir  # Uncomment this line to analyse a project which is not a java project. # The value of the property must be the key of the language.#sonar.language=cobol # Additional parametersmy.property=value

 例子:

     >> 项目路径如下:

        + src\java 源代码

        + src\test 测试类源代码

        + src\config 项目配置文件

     >> 在与src同级的目录里创建名为sonar-project.properties的文件, 图片如下:

                     

    >> 执行sonar.sh start开始检查代码啦. 之后在打开Sonar的页面()就可以看到该项目的代码检查啦.

转载于:https://my.oschina.net/sword4j/blog/70756

你可能感兴趣的文章
[IOS]clang diagnostic、Wprotocol ..
查看>>
HTML4.01规范-HTML文档的顶层结构(3)
查看>>
11个鲜为人知的实用Linux命令 - Part 2
查看>>
我国今日接连发生4起地震 震级均在3级以上
查看>>
优化PhoneGAP的Splashscreen 类
查看>>
增强 wp_list_authors 显示文章最多的作者
查看>>
代码:显示查询的日历
查看>>
完整的目标管理三段俱全
查看>>
AD 脚本kixtart运用之六(outlook邮件批量生成签名)
查看>>
优化SQL查询:如何写出高性能SQL语句
查看>>
简单易用的库存管理软件、进销存软件
查看>>
docker WARNING: IPv4 forwarding is disabled. 解决方法
查看>>
Tomcat+Nginx+Memcached集群部署
查看>>
通过FFMPEG代码学习函数指针和指针函数
查看>>
puppet 基础篇
查看>>
到底怎么样才叫看书?
查看>>
python 将ipv4的格式转换
查看>>
C语言宏的副作用的简单实例
查看>>
关于C语言结构体对齐的学习
查看>>
富文本框
查看>>