0

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 e.g. "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 e.g. modules, sourceDirectory etc. correctly.

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

Thanks in Advance.

Modou
  • 1
  • 1
  • 1
  • that is the nice thing about gradle, you do not need to take care of a lot of things. -> if you really use gradle to build all your files, you can just apply the sonarqube gradleplugin, provide the project keys etc. as described in the plugin docu, and it will detect your source automatically, when you add jacoco for test coverage, it will also detected automatically – Simon Schrottner May 09 '18 at 10:13

1 Answers1

0

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

Simon Schrottner
  • 4,146
  • 1
  • 24
  • 36