How do I prevent the Gradle sonarqube task from running tests?

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube Enterprise
    SonarQube Gradle plug-in 2.7

  • what are you trying to achieve
    I am trying to scan my codebase, but trying to run all my tests sequentially takes too long and times out. We already run our tests in batches in parallel.

I’m trying to disable running tests during the Gradle sonarqube task.

Tried to remove the dependencies:


Tried to remove the dependencies on subprojects:



In fact this question was also raised internally. I think we’re going to drop the dependency, altho I don’t have a ticket number to give you right now. In the meantime, this workaround was suggested: sonarqube.dependsOn.remove("test")


1 Like

Thank you, Ann. I’m looking forward to that change.

The dependency on test makes a lot of sense on a well-factored codebase with fast tests, but it collides badly with our monolithic codebase with its huge, slow testsuite :slight_smile:

Has the workaround been validated?

I got this when I tried it:

17:39:29: Executing task 'sonarqube'...

> Task :buildSrc:compileJava NO-SOURCE
> Task :buildSrc:compileGroovy UP-TO-DATE
> Task :buildSrc:processResources UP-TO-DATE
> Task :buildSrc:classes UP-TO-DATE
> Task :buildSrc:jar UP-TO-DATE
> Task :buildSrc:assemble UP-TO-DATE
> Task :buildSrc:compileTestJava NO-SOURCE
> Task :buildSrc:compileTestGroovy NO-SOURCE
> Task :buildSrc:processTestResources NO-SOURCE
> Task :buildSrc:testClasses UP-TO-DATE
> Task :buildSrc:test NO-SOURCE
> Task :buildSrc:check UP-TO-DATE
> Task :buildSrc:build UP-TO-DATE

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/example/Documents/work/example/build.gradle' line: 24

* What went wrong:
A problem occurred evaluating root project 'example'.
> Could not get unknown property 'dependsOn' for object of type org.sonarqube.gradle.SonarQubeExtension.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at

Could not get unknown property 'dependsOn' for object of type org.sonarqube.gradle.SonarQubeExtension.
17:39:30: Task execution finished 'sonarqube'.

I did something significantly more invasive to work around this and something direct like that would be a big improvement.

I added this to each project:

test.exclude '**/**'

task realtest(type: Test, description: 'Runs the tests.', group: 'Verification') {
    include '**/**'

This is very invasive, but it worked.


Okay, you caught me. That workaround was tossed out in an internal thread, but no one chimed in to say “yeah, that!”. I passed it on hoping that the lack of a “no!” was a “yeah, sure”. Sorry I caused you extra trouble with it & glad you did find a solution.


1 Like

No extra trouble. I was able to quickly invalidate it. I just thought I’d let you know.


I have an open pull request against sonar-scanner-gradle:

This may not be the preferred design, but I think it’s a good starting point.

1 Like

And FYI:

1 Like

it may not be on target for what you wanted, but all I did was :

gradle clean build sonarqube -x test


Thanks! Using the latest scanner plugin, I still had to use -x compileJava -x compileTestJava.

'ello :wave: 2021 is calling :innocent:

on a more serious note … we are actually experiencing this, too … i am currently challenging our build engineers with what i need to upgrade SonarQube from 8.9 (java11 optional) to 9.x (java11 mandatory)

The documentation here explains a (Jenkins) way for maven (but not for gradle) and the challenges mentioned here in this thread surface in our builds. (the gradle task dependencies, even optimized already, need some -x administration)

If anything, would it maybe be possible to address the documentation of working ways for both tools (maven + gradle) in the beforementioned existing docs? :pray:

it would be nice to be able to use that as a reference for ppl asking :+1:

(for reference: here you can find a newer episode of the same)