RE: Configure SonarQube in my workspace

Patricia Hevia, modified 7 Years ago. Junior Member Posts: 69 Join Date: 3/24/11 Recent Posts
Hello,

I am working with Liferay DXP and I would like integrate SonarQube in my workspace, I am using gradle.

My workspace is called: test-workpace

My gradle.properies file (path: test-workspace/gradle.properties) is:
systemProp.sonar.host.url=http://localhost:9000
systemProp.sonar.sourceEncoding=UTF-8
systemProp.sonar.forceAuthentication=true
systemProp.sonar.login=<mytoken>

# Definición de variables para el proyecto.
description = 'Gradle - Sample Project'
group = 'com.test.sonarqube.gradle'
version = '1.0.0'</mytoken>


My build.gradle file (path: test-workspace/build.gradle) is:
buildscript {
        repositories {
                mavenLocal()
                jcenter()
                maven {
                        url "https://plugins.gradle.org/m2/"
                }
        }
        dependencies {
                classpath group: "org.sonarsource.scanner.gradle", name:"sonarqube-gradle-plugin", version:"2.5"
        }
}
group = 'com.test.sonarqube.gradle'
apply plugin: "org.sonarqube"


When I execute gradle sonarqube all workspace is scanned but I would like to configure each modules like a project in SonarQube.

Someone know how to configure gradle files to do it?.

Thank you very much!
thumbnail
Sushil Patidar, modified 7 Years ago. Expert Posts: 467 Join Date: 10/31/11 Recent Posts
Hi,

i think configuration of following properties in each project may solve your issue.
sonar.projectKey [${project.group}:]${project.name} for root module
<root module key>:<module path> for submodules

sonar.projectName ${project.name}


Regards
thumbnail
Vishal Panchal, modified 6 Years ago. Expert Posts: 289 Join Date: 5/20/12 Recent Posts
Thanks Sushil, that worked.
thumbnail
Lokesh Sharma, modified 5 Years ago. Junior Member Posts: 54 Join Date: 7/30/15 Recent Posts
Hi Vishal,
Can you please provide you gradle file Facing same issue
Rafal Pydyniak, modified 5 Years ago. New Member Posts: 4 Join Date: 12/6/16 Recent Posts
Hello,
I know it's an old topic but if that helps you can just run it like: 
./gradlew sonarqube \
  -Dsonar.projectKey=test2 \
  -Dsonar.host.url=http://localhost:9000 \
  -Dsonar.login=115ee4c271411c118e7935ee705bdebcdf714b4a
you just need to provide your projectKey, url of your SonarQube and your token as login (the one you generated when you created a project - if you don't have it you can always generate it again in your account settings in security tab)The only thing you need for that is to have sonarqube plugin in build.gradle
plugins {
  id "org.sonarqube" version "2.7"
}
I used to use that (before Jenkins) and that worked but I've only tested in on particular modules not the whole project (just because we wanted to have few SonarQube projects for one workspace because we have quite a lot modules).If perhaps you wanted to use Jenkins instead you can check this SonarQube with Jenkins and Liferay integration tutorial
Best regards and hope that helpsRafał Pydyniak