How to specify test task run by Gradle SonarQube plugin

Viewed 6729

I am using Gradle with the sonarqube plugin and triggering it using

gradle sonarqube

However, it is calling the built in "test" task which runs all types of tests including the integration tests which do not all pass at the moment. I want to be able to specify that the sonarqube task use something like a "unitTest" task instead of the "test" task which runs everything.

Other people on the team run cucumber tests within the IDE which also uses the test task, so currently when I exclude cucumber tests in the main "test" task, they have to comment that excludes out in order for their cucumber tests to be kicked off, which is not ideal.

I am including sonarqube using the below syntax:

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

How can I make the sonarqube task use another test task?

Update:

Got it to work with the below code, made subprojects run their unitTests first to generate required test report data and then run sonarqube task.

// Removes the dependency on main test task and runs unitTests for test code coverage statistics
tasks['sonarqube'].with {
    dependsOn.clear()
    subprojects.each { dependsOn("${it.name}:unitTests") }
}

dependsOn.clear() clears all dependencies, so if there were multiple, I would probably have to do something like

taskName.enabled=false

and then re-enable it after the task was done unless there is a easier way to do it? I've tried dependsOn.remove("test") but that didn't work.

1 Answers
Related