How to skip test task when running sonarqube task? - gradle

When I execute sonarqube task, by default test task runs. How can I configure Gradle to not run tests when I specifically run sonarqube.
I want to configure this build.gradle.kts.
When I run
./gradlew sonarqube -x test
then tests are not executed.
I want to achieve the same by configuring in the build.gradle.kts file.

Related

Gradle with multiple subproject running tests

Let's assume that I have such structure of a gradle project:
:app:api
:app:domain
:app:infra
:app:libs:lib1
:app:libs:lib2
Infra depends on lib1 and lib2.
As far as I know, if you run task test for infra, gradle by default runs all test tasks for all the dependent projects, which are:
:app:libs:lib1
:app:libs:lib2
How can I disable this functionality? I want to run gradlew app:infra:test, I want to run tests just in infra and not to run tests in lib1 and lib2?
If I run gradlew test, then I want to run all the tests.

Intellij IDEA - skip jaCoCo while running individual tests

I have gradle JaCoCo configuration as advised by the docs:
test {
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test
}
I have Intellij IDEA configuration to run tests with Gradle. Currently when I run individual tests from IDEA, it also launches jaCoCo coverage report, which takes time and I would like to avoid.
So I would like:
to keep my gradle configuration so that coverage reports run every time I run build
Do not run JaCoCo when running tests from IDEA
I have tried changing gradle tasks definition in IDEA to include -x jacocoTestReport, but it has no effect. I tried to change test run configuration, but its getting reset for every new test,
Please try to set the Run tests using to "Intellij IDEA" from Preferences/Settings | Build, Execution, Deployment | Build Tools | Gradle .
enter image description here

Running gradle commands inside a task

Is there any way by which i can run gradle clean, gradle compileand gradle publish commands inside a gradle task in build.gradle on a windows pc
You can use taskX.dependsOn taskY where taskX is the task you will be running (in this case, build) and where taskY is the task that must be run before the current task. You could also use taskY.shouldRunAfter taskX for a task that should run after the current task. Note that these statement shouldn't be called from within the task.
build.dependsOn publish will run the publish task before running the build task.
I suggest you read through Ordering Tasks in the gradle doc.
If you really need to call a task from another task, you can, but there are better options - such as those above. Using tasks.taskX.execute() will do what you're looking for. Where taskX is the task you want to execute. This can be called from within a task.
To address your comment.
This code will run the tasks: clean, compile and publish before build is executed:
build.dependsOn clean
build.dependsOn compile
build.dependsOn publish
This code will run the tasks: clean, compile and publish after build has been executed:
build.shouldRunAfter clean
build.shouldRunAfter compile
build.shouldRunAfter publish
This code will run the task: clean before build is executed and run: compile and publish after build has been executed:
build.dependsOn clean
build.shouldRunAfter compile
build.shouldRunAfter publish
This is probably the code you're looking for. Add the configuration which best suits your needs before the build task has been declared. Then when executing build.gradle, execute the task build from the command line.

When does SonarQube plugin run unit test?

I'm using SonarQube4.2 with jekins plugin. I configured Sonar as Post-Build Action on Jenkins, and It's work fine. I'm wondering that if maven compiles test sources before executing the sonar action, sonar automatically run these test units, but maven only compiles main sources, then sonar doesn't run unit tests. If Jenkins execute mvn test phase before Sonar as Post=Build Action, Jenkins duplicate running unit tests. I want to compile sources, running unit tests and executing Sonar, hence I configured mvn test-compile with Post-Build Action for Sonar in Job. Is it usual way? Does any body knows better way to executiong sonar with Jenkins.
Regards

How do I stop sonar running tests?

I'm looking at using Sonar to reduced the number of plugins I've had to install in Jenkins to get some decent code analysis (and sonar seems to do more and present it better). However when I kick of the sonar job the JUnit / Concordion tests are executed. I don't want these tests run as Jenkins is already executing the tests.
How do I stop the tests executing and just perform code analysis?
I've installed sonar 3.7.3 and executing using the Gradle sonar-runner plugin and specifying the :sonarRunner task.
I'm just facing the same issue and it seems that you can run :sonarqube -x test to avoid having tests run before.
You can set the sonar.dynamicAnalysis property to false. This will skip tests and only perform the static analysis part.
See http://docs.codehaus.org/display/SONAR/Analysis+Parameters#AnalysisParameters-OptionalParameters

Resources