Skipping project in command line

I have a multi-module android project that I’m trying to configure.
It’s using gradle and kotlin and I’m following these resources: gradle docs , sample project

I am using

plugins {
 id "org.sonarqube" version "3.4.0.2513"
}

The project contains two application modules and I’ve setup two sonar cloud projects. Now I want my reports to not analyze the content of the other app in each of these projects.

The documentation clearly states that to skip a project we should do:

// build.gradle
project(":project2") {
    sonarqube {
        skipProject = true
    }
}

( skipProject is private and it should be isSkipProject)

I have two jenkins setups and would like to somehow skip the unused app from within the pipeline.
I have tried to make a gradle task that skips the module:

tasks.register("skipModule") {
    group = "Reporting"
    doLast {
        project(":theModule") {
            sonarqube {
                isSkipProject = true
            }
        }
    }
}

But as the task is run after the configuration and the sonareqube task properties don’t get updated.
I also tried to use the maven command line equivalent: :<app>.sonar.skip=true but I’m not sure it’s actually taken into account because I can still see the new lines of the project I’m supposed to have skipped and all its lint issues.

So how can I, at execution time, tell the sonarqube task to skip a project?

After having tried a bunch of different things including trying to adapt this reply to my use case (I want the analyses of my apps to include the util/common libs), I’ve come to the conclusion that there is no solution for my problem.
It seems that once the task is configured, there is no coming back. In a multi-module project the only way of doing that is in the project root, and there is no way to use command line parameters to skip a module (I tried overriding the sonar.modules and doing :<app>.sonar.skip=true, but to no avail…)

But if someone does know of a way to do this (@ devs it would be nice to have) I’m interested.

Looking at the bright side of things I found a way to get to something that kind of works by setting within sonarcloud’s Administration >General Settings> Analysis Scope patterns to not take into account the other app.

Hello @PaulLandry,

Thank you for reaching out to us!
Regarding to this doc Gradle scanner, have you tried to add directly in the build.gradle file of subModule project that you are analysing , to exclure the other submodule from your analysis as below

project(":name_of_your_other_submodule") {
    sonarqube {
        skipProject = true
    }}

I can imagine that each build is working on one of the sub-modules, so it might igonre the other one.
I cannot garantie that it will work but you still can try it!

Regards,
Nawar

Hello @Nawar_Hamo,
the thing is that skipping modules that you know from the start won’t be needed is easy and can be done directly from within the subprojects block of the root build.gradle, my need is to skip a module “dynamically” when I don’t know from the start which module to skip.
Since my last post, I actually figured out a way to do this, as I finally understood that gradle project arguments (-P) actually re-trigger a configuration phase. So when using the command line, I can set an argument that I can then catch in the subprojects block and then skip the undesired module.

1 Like

Hey @PaulLandry,

Thank you for sharing the solution that you found with us!

Regards,
Nawar

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.