maven sonar jenkins android 工程 step by step

上篇我们讲到 maven  jenkins android工程进行编译,本篇讲解在此基础上

如何配置sonar分析:

    

下载sonar

     版本:3.0

     下载地址:http://www.sonarsource.org/downloads/

下载完成之后,要注意一个问题,官方的说明是不要安装在以数字开头的目录中。所以我们就不要解压在数字开头的目录中。

安装sonar ("//"号部分可以参考,无实际安装必要,用sonar自带的数据库即可)

1、安装JDK-1.5以上版本。

// 2、安装oracle10G以上版本。

//3、在数据库中创建新用户sonar密码为sonar 并给用户赋权

   用户和密码可以自定义,如果自定义需要更改sonar-3.0\conf\sonar.properties配置文件中得sonar.jdbc.usernamesonar.jdbc.password

//4、配置sonar-3.0\conf\sonar.properties文件。

1)配置启动的http端口

sonar.web.host:                           192.168.140.11

sonar.web.port:                           8082

sonar.web.context:                        /

//三句前本来被注释,取消注释

2)取消oracle连接的注释,并输入自己数据库的url地址,同时将默认的sonar.jdbc.url屏蔽

sonar.jdbc.url:                            jdbc:oracle:thin:@localhost:1521:orcl10g

# Optional properties

sonar.jdbc.driverClassName:                oracle.jdbc.OracleDriver

sonar.jdbc.validationQuery:                 select 1 from dual

//5、复制oracle驱动

复制ojdbc14.jar,到sonar-3.0\extensions\jdbc-driver\oracle目录下,驱动得版本需要同连接的数据库版本一致

6、进入bin中,选择适合自己系统,运行sonar.sh,如果是windows运行bat

运行sonar-3.0\bin\windows-x86-32\StartSonar.bat,打开相应的网页:http://localhost:9000测试是否配置成功,这里的页面链接跟前头的http配置有关

 


# This file must contain only ISO 8859-1 characters
# see http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Properties.html#load(java.io.InputStream)
#
# To use an environment variable, use the following syntax :  ${env:NAME_OF_ENV_VARIABLE}
# For example :
#   sonar.jdbc.url: ${env:SONAR_JDBC_URL}
#
#
# See also the file conf/wrapper.conf for JVM advanced settings
#---------------------------------------------------------


#---------------------------------------------------------
# WEB SETTINGS - STANDALONE MODE ONLY
# These settings are ignored when the war file is deployed to a JEE server.
#---------------------------------------------------------
# Listen host/port and context path (for example / or /sonar). Default values are 0.0.0.0:9000/.
#sonar.web.host:                           127.0.0.1
#sonar.web.port:                           9000
#sonar.web.context:                        /                                        //这部分都是默认,不用动

# Log HTTP requests. Deactivated by default.
#sonar.web.jettyRequestLogs: ../../logs/jetty-yyyy_mm_dd.request.log
#sonar.web.jetty.threads.min:              5
#sonar.web.jetty.threads.max:              50
#sonar.web.jetty.threads.low:              10

#-----------------------------------------------------------------------
# DATABASE
#
# IMPORTANT : the embedded database H2 is used by default.
# It is recommended for tests only. Please use an external database
# for production environment (MySQL, Oracle, Postgresql, SQLServer)
#
#-----------------------------------------------------------------------

#----- Credentials
# Permissions to create tables and indexes must be granted to JDBC user.
# The schema must be created first.
sonar.jdbc.username:                       sonar
sonar.jdbc.password:                       sonar

#----- Embedded database H2
# 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:h2:tcp://localhost:9092/sonar
#sonar.jdbc.driverClassName:                org.h2.Driver

# directory containing H2 database files. By default it's the /data directory in the sonar installation.
#sonar.embeddedDatabase.dataDir:
# H2 embedded database server listening port, defaults to 9092
#sonar.embeddedDatabase.port:               9092


#----- MySQL 5.x
# Comment the embedded database and uncomment the following line to use MySQL
#sonar.jdbc.url:                            jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true

# Optional properties
#sonar.jdbc.driverClassName:                com.mysql.jdbc.Driver


#----- Oracle 10g/11g
# To connect to Oracle database :
#
# - It's recommended to use the latest version of the JDBC driver (either ojdbc6.jar for Java 6 or ojdbc5.jar for Java 5).
#   Download it in http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
# - Copy the driver to the directory extensions/jdbc-driver/oracle/
# - Comment the embedded database and uncomment the following line :
#sonar.jdbc.url:                            jdbc:oracle:thin:@localhost/XE

# Optional properties
#sonar.jdbc.driverClassName:                oracle.jdbc.OracleDriver

# Uncomment the following property if the Oracle account has permissions to access multiple schemas,
# for example sonar schemas with different versions. In that case, use the same property during project analysis
# (-Dsonar.jdbc.schema=<schema>)
# The schema is case-sensitive.
#sonar.jdbc.schema:                         sonar


#----- PostgreSQL 8.x/9.x
# Comment the embedded database and uncomment the following property to use PostgreSQL
#sonar.jdbc.url:                            jdbc:postgresql://localhost/sonar

# Optional properties
#sonar.jdbc.driverClassName:                org.postgresql.Driver

# Uncomment the following property if the PostgreSQL account has permissions to access multiple schemas,
# for example sonar schemas with different versions. In that case, use the same property during project analysis
# (-Dsonar.jdbc.schema=<schema>)
#sonar.jdbc.schema:                         public


#----- Microsoft SQLServer
# The Jtds open source driver is available in extensions/jdbc-driver/mssql. More details onhttp://jtds.sourceforge.net
#sonar.jdbc.url:                            jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor

# Optional properties
#sonar.jdbc.driverClassName:                net.sourceforge.jtds.jdbc.Driver


#----- Connection pool settings
sonar.jdbc.maxActive:                      20
sonar.jdbc.maxIdle:                        5
sonar.jdbc.minIdle:                        2
sonar.jdbc.maxWait:                        5000
sonar.jdbc.minEvictableIdleTimeMillis:     600000
sonar.jdbc.timeBetweenEvictionRunsMillis:  30000


#---------------------------------------------------------
# UPDATE CENTER
#---------------------------------------------------------

# The Update Center requires an internet connection to request http://update.sonarsource.org
# It is activated by default:
#sonar.updatecenter.activate=true

# HTTP proxy (default none)
#http.proxyHost=
#http.proxyPort=

# NT domain name if NTLM proxy is used
#http.auth.ntlm.domain=

# SOCKS proxy (default none)
#socksProxyHost=
#socksProxyPort=

# proxy authentication. The 2 following properties are used for HTTP and SOCKS proxies.
#http.proxyUser=
#http.proxyPassword=

#---------------------------------------------------------
# NOTIFICATIONS
#---------------------------------------------------------

# Delay (in seconds) between processing of notification queue
sonar.notifications.delay=60

 

maven中配置sonar

修改maven配置文件

%MAVEN_HOME%\conf\setting.xml中输入下面内容:  

<profiles>

<profile>

            <id>sonar</id>

            <activation>

                <activeByDefault>true</activeByDefault>

            </activation>

            <properties>

                <!-- EXAMPLE FOR MYSQL -->

                <sonar.jdbc.url>

                  jdbc:oracle:thin:@localhost:1521:orcl10g

                </sonar.jdbc.url>

                <sonar.jdbc.driverClassName>oracle.jdbc.OracleDriver</sonar.jdbc.driverClassName>

                <sonar.jdbc.username>sonar</sonar.jdbc.username>

                <sonar.jdbc.password>sonar</sonar.jdbc.password>

 

                <!-- SERVER ON A REMOTE HOST -->

                <sonar.host.url> http://192.168.140.11:8082/</sonar.host.url>

            </properties>

    </profile>

  </profiles>

执行命令

在命令行进入到项目文件的目录中去,然后再输入mvn sonar:soanr进行测试

查看结果

在浏览器中输入http://localhost:9000 或者http://10.120.23.101:9000 或者http://127.0.0.1:9000 查看结果。

jenkins集成,构建时自动进行sonar分析

配置

打开jenkinsurl http://10.120.23.101:8080/jenkins

点击需要进行sonar分析的项目,在左侧的菜单中选择配置。

 

 


 

3.2构建并查看sonar报告

选择jenkins项目,点击立即构建

构建完成后在浏览器中输入http://127.0.0.1:9000/查看结果

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值