maven + sonar, gradle + sonar

本文详细介绍了Sonar的安装步骤、环境变量设置、启动Sonar、登录Sonar页面、检查代码问题、Eclipse插件安装、服务器配置、与Maven和Gradle的集成方法,包括相关命令和配置细节。

sonar installation and configuration

  1. Download sonar
    http://downloads.sonarsource.com/sonarqube/
  2. Decompression sonar package for installation
  3. Set sonar environment variable
    SONAR_HOME: “D:\sonarqube”
    PATH: “%SONAR_HOME%\bin\windows-x86-64”
  4. Start-up sonar
    CMD: StartSonar
    这里写图片描述
  5. log into sonar
    http://localhost:9000/
  6. check issue in sonar web page
    这里写图片描述

eclipse plug-in installation

  1. installation from “Eclipse Marketplace”
    这里写图片描述
  2. Configuration sonar server
    这里写图片描述

sonar with maven

  1. pom.xml fragment for sonar
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <sonar.host.url>http://localhost:9000</sonar.host.url>
        <sonar.exclusions>**/*.class, **/*.groovy, src/main/java/spark/*</sonar.exclusions>
    </properties>

Note: sonar uses h2 as default database
2. maven CMD for sonar
CMD: mvn sonar:sonar
3. Analyze maven project in sonar GUI
http://localhost:9000/

sonar with gradle

  1. build.gradle fragment for sonar
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: "sonar-runner"

group = 'com.shuai.gradle.demo'
description = 'hello gradle for demo'

sourceCompatibility = 1.7
version = '1.0'

jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart',
        'Implementation-Version': version
    }
}

repositories { maven { url "http://scm0.access.nsn.com/nexus/content/groups/unify/" } }

dependencies {
    compile group: 'commons-io', name: 'commons-io', version: '2.+'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.+'
    compile group: 'commons-collections', name: 'commons-collections', version: '3.+'
    testCompile group: 'junit', name: 'junit', version: '4.+'
}

sonarRunner {
    sonarProperties {
        property "sonar.host.url", "http://localhost:9000"

        property "sonar.jdbc.url", "jdbc:h2:tcp://localhost:9092/sonar"
        property "sonar.jdbc.driverClassName", "org.h2.Driver"
        property "sonar.jdbc.username", "sonar"
        property "sonar.jdbc.password", "sonar"
    }
}

test { systemProperties 'property': 'value' }

uploadArchives {
    repositories {  flatDir { dirs 'repos' }  }
}
  1. gradle CMD for sonar
    CMD:
    gradle build cleanEclipse -x test
    gradle sonarRunner
  2. log into sonar
    http://localhost:9000/

analyze codes via sonar in eclipse

  1. associate with sonarQube
    这里写图片描述
  2. analyze codes via sonar
    这里写图片描述

这里写图片描述

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值