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.
login property in your command line or you configure it as part of your gradle. properties file. Execute gradle sonarqube -Dsonar. login=yourAuthenticationToken and wait until the build has completed, then open the web page indicated at the bottom of the console output.
Run Gradle testsIn your Gradle project, in the editor, create or select a test to run. From the context menu, select Run <test name>. icon in the left gutter. If you selected the Choose per test option, IntelliJ IDEA displays both Gradle and JUnit test runners for each test in the editor.
Advertisements. The test task automatically detects and executes all the unit tests in the test source set., Once the test execution is complete, it also generates a report. JUnit and TestNG are the supported APIs. The test task provides a Test.
The sonarqube
tasks simply depends on the test
task by default, according to the docs:
To meet these needs, the plugins adds a task dependency from sonarqube on test if the java plugin is applied.
You can easily remove this task dependency and add your own ones:
task unitTest {
doLast {
println "I'm a unit test"
}
}
tasks['sonarqube'].with {
dependsOn.clear()
dependsOn unitTest
}
Now, only the unitTest
task (and its dependencies) will be executed whenever you execute the sonarqube
task. Please note, that dependsOn
is just a list of dependency entries. You can modify it in many different ways.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With