简体   繁体   中英

How to retrieve sonar-project-properties from gradle based project

current state

I am currently working on a java application that is supposed to clone different projects locally and the generate the sonar-project.properties file to prepare for SonarQube analysis.

The application can do this for maven based projects by detecting the "pom.xml" file and getting the needed property eg "sonar.modules" from the tag in that file and writes them into the sonar-project.properties file of that project.

Question

Now I'm supposed to expand my program to analyze Gradle based projects. Since I have never worked with Gradle my question is where I can find the information I need in order to configure the sonar-project.properties file eg modules, sourceDirectory etc. correctly.

This is my first SOF-question so please write a comment if you need any additional information.

Thanks in Advance.

If you are fully using gradle to build you project this will be quiet easy and handy to achieve. most important part is that you take a close look at the gradle plugin documentation and examples - https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle

i will add here a short gradle build script, based on a start.spring.io project with gradle. When you call gradle build sonarqube this will

  • build your application
  • run your tests, with coverage as the jacoco plugin is applied too
  • upload everything to the specified sonar server

example:

buildscript {
    ext {
        springBootVersion = '2.0.1.RELEASE'
    }
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2'
        classpath "org.ajoberstar:grgit:2.2.0"
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'jacoco'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.sonarqube'

group = 'net.gradle.testing'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

sonarqube {
    properties {
        System.setProperty('sonar.host.url', 'host URL')
    }
}

But as already stated, to set special properties, or how the Proejct key and name is set, you best check the documentation of the scanner :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM