From 92c974d443a73bf081817e36cb4830cb6a28515d Mon Sep 17 00:00:00 2001 From: Gunnar Hillert Date: Wed, 11 Jan 2012 14:52:59 -0500 Subject: [PATCH] INT-2393 Add Sonar Support (Gradle Plugin) INT-2393 - Changes in Build.gradle based on Code Review * Changed line to *jvmArgs "-javaagent:${configurations.jacoco.asPath}=destfile=${buildDir}/jacoco.exec,includes=org.springframework.integration.*"* * Added *props["sonar.jacoco.reportPath"] = "${buildDirName}/jacoco.exec" to make build work with default build directory* * Therefore able to remove: *buildDir = "target"* * Moved *sonar* block to bottom of build script * Added comments around the **configurations** block * Switched to use Gradle Properties instead of System Properties for Sonar parameters INT-2393 - rootProject.hasProperty works * More simplifications after finding out that **rootProject.hasProperty** works inside the Sonar closure INT-2393 Based on code review: Fixed build.gradle Based on Code Review, converted println statement to logger.info in build.gradle --- build.gradle | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/build.gradle b/build.gradle index 3e75dd7203..5e85f65b9e 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,7 @@ allprojects { } subprojects { subproject -> + apply plugin: 'java' apply plugin: 'maven' apply plugin: 'eclipse' @@ -60,6 +61,12 @@ subprojects { subproject -> } } + // See http://www.gradle.org/docs/current/userguide/dependency_management.html#sub:configurations + // and http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ConfigurationContainer.html + configurations { + jacoco //Configuration Group used by Sonar to provide Code Coverage using JaCoCo + } + // dependencies that are common across all java projects dependencies { testCompile "cglib:cglib-nodep:$cglibVersion" @@ -70,6 +77,7 @@ subprojects { subproject -> testCompile "org.hamcrest:hamcrest-all:1.1" testCompile "org.mockito:mockito-all:$mockitoVersion" testCompile "org.springframework:spring-test:$springVersion" + jacoco group: "org.jacoco", name: "org.jacoco.agent", version: "0.5.3.201107060350", classifier: "runtime" } // enable all compiler warnings; individual projects may customize further @@ -79,6 +87,7 @@ subprojects { subproject -> test { // suppress all console output during testing unless running `gradle -i` logging.captureStandardOutput(LogLevel.INFO) + jvmArgs "-javaagent:${configurations.jacoco.asPath}=destfile=${buildDir}/jacoco.exec,includes=org.springframework.integration.*" } bundlor { @@ -876,6 +885,41 @@ reference { sourceDir = file('src/reference/docbook') } +apply plugin: 'sonar' + +sonar { + + if (rootProject.hasProperty('sonarHostUrl')) { + server.url = rootProject.sonarHostUrl + } + + database { + if (rootProject.hasProperty('sonarJdbcUrl')) { + url = rootProject.sonarJdbcUrl + } + if (rootProject.hasProperty('sonarJdbcDriver')) { + driverClassName = rootProject.sonarJdbcDriver + } + if (rootProject.hasProperty('sonarJdbcUsername')) { + username = rootProject.sonarJdbcUsername + } + if (rootProject.hasProperty('sonarJdbcPassword')) { + password = rootProject.sonarJdbcPassword + } + } + + project { + dynamicAnalysis = "reuseReports" + withProjectProperties { props -> + props["sonar.core.codeCoveragePlugin"] = "jacoco" + props["sonar.jacoco.reportPath"] = "${buildDirName}/jacoco.exec" + } + } + + logger.info("Sonar parameters used: server.url='${server.url}'; database.url='${database.url}'; database.driverClassName='${database.driverClassName}'; database.username='${database.username}'") + +} + task api(type: Javadoc) { group = 'Documentation' description = 'Generates aggregated Javadoc API documentation.'