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

gradle
jenkins

(Alain O'Dea) #1
  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube Enterprise 7.4.0.18908
    Scanner 3.2.0.1227
    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:

project.task['sonarqube'].dependsOn.remove(test)

Tried to remove the dependencies on subprojects:

rootProject.task['sonarqube'].dependsOn.remove(subproject.task['test'])

(G Ann Campbell) #2

Hi,

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")

 
Ann


(Alain O'Dea) #3

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 https://help.gradle.org

BUILD FAILED in 1s
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.


(G Ann Campbell) #4

Hi,

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.

 
:frowning_face:
Ann


(Alain O'Dea) #5

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


(Alain O'Dea) #6

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.


(G Ann Campbell) #7

And FYI: https://jira.sonarsource.com/browse/SONARGRADL-59