maven + sonar, gradle + sonar
sonar installation and configuration
- Download sonar
http://downloads.sonarsource.com/sonarqube/ - Decompression sonar package for installation
- Set sonar environment variable
SONAR_HOME: “D:\sonarqube”
PATH: “%SONAR_HOME%\bin\windows-x86-64” - Start-up sonar
CMD: StartSonar
- log into sonar
http://localhost:9000/ - check issue in sonar web page
eclipse plug-in installation
- installation from “Eclipse Marketplace”
- Configuration sonar server
sonar with maven
- 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
- 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' } }
}
- gradle CMD for sonar
CMD:
gradle build cleanEclipse -x test
gradle sonarRunner - log into sonar
http://localhost:9000/
analyze codes via sonar in eclipse
- associate with sonarQube
- analyze codes via sonar