Using SonarQube Server Enterprise Edition v10.8.1 and Gradle Plugin 6.0.1.5171
Deployed by GitHub Actions
Hello!
I’m running into some issues configuring SonarQube to run only over a subset of tests.
To avoid spending a lot of time while running the unit tests on my app I’m trying to only run and build those related to the code that has been updated on the PR, but SonarQube scan fails because it requests the .jar files generated when running the other tests from the project, which are obviously not generated because the tests are not run.
Since it will depend on the PR I cannot just skip the modules from the Gradle files, but instead I need a command that I can apply on the Github action running the scan.
I have already tried some commands like skipCompile and skipTests, but those seem to do nothing or are deprecated, so none of the solutions I tested worked.
So that we know clearly what you’re dealing with, can you provide the full analysis log, please?
The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.
First, since I can’t get the analysis log on a failing run, I’ll post the error I get when it fails, just to give a bit of context:
> Task :sonar FAILED
Task listener: task :sonar failed
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':sonar'.
> Could not resolve all files for configuration ':xxxxxxxxxxx:debugUnitTestCompileClasspath'.
> Failed to transform testing-annotations-jvm-yyyyyyy.jar (project :testing:testing-annotations) to match attributes {artifactType=android-classes-jar, org.gradle.category=library, org.gradle.jvm.environment=standard-jvm, org.gradle.libraryelements=jar, org.gradle.usage=java-api, org.jetbrains.kotlin.platform.type=jvm}.
> Execution failed for IdentityTransform: /__w/xxxxxxxxx/testing/testing-annotations/build/libs/testing-annotations-jvm-yyyyyyy.jar.
> File/directory does not exist: /__w/xxxxxxxxx/testing/testing-annotations/build/libs/testing-annotations-jvm-yyyyyyy.jar
For a working build, which includes those logs:
Sensors : JaCoCo XML Report Importer -> Kotlin Sensor -> Gradle Sensor -> KotlinSurefireSensor -> Java Config Sensor -> IaC Docker Sensor -> EnterpriseTextAndSecretsSensor
[org.sonarsource.scanner.lib.internal.ScannerEngineLauncher] Sensor JaCoCo XML Report Importer [jacoco]
[org.sonarsource.scanner.lib.internal.ScannerEngineLauncher] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[org.sonarsource.scanner.lib.internal.ScannerEngineLauncher] Reading report '/__w/xxxxxxxxx/build/reports/jacoco/report.xml'
***
Lots of files, all of them with "generated metadata with charset 'UTF-8'"
***
[org.sonarsource.scanner.lib.internal.ScannerEngineLauncher] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=348ms
Hello!
Sorry, thought I had changed to the --info. Here is the output using that one. I had to remove the Configure project step for the non related parts of the build (company policy). Checked it and all of them are nearly identical to the one that is shown there.
Successfully started process 'command '/__w/xxxxxxxxx/xxxxxxxxx/apps/xxxxxxxxx/build/tmp/sentry-cli-2.33.1.exe''
[sentry] Failed to execute sentry-cli info. Error Output: error: Auth token is required for this request. Please run `sentry-cli login` and try again!
It’s a failure, but it doesn’t seem to be what errors-out the job.
Then we have the stacktrace that ends with this Caused by:
…
Caused by: java.lang.IllegalArgumentException: File/directory does not exist: /__w/xxxxxxxxx/xxxxxxxxx/testing/testing-annotations/build/libs/testing-annotations-jvm.jar
So again, the failure is nominally attributed to the sonar job because the failing task apparently ran as a precursor. But it’s not SonarQube analysis that’s failing.
Successfully started process 'command '/__w/xxxxxxxxx/xxxxxxxxx/apps/xxxxxxxxx/build/tmp/sentry-cli-2.33.1.exe''
[sentry] Failed to execute sentry-cli info. Error Output: error: Auth token is required for this request. Please run `sentry-cli login` and try again!
This one is always there, even on successful runs.
The thing is that it only fails when running a subset of tests, and not all of them (since all the .jar files are generated).
But if it’s not Sonar what’s failing, executing only a subset of tests and running a Sonar scan is possible, right? Even if the project is configured with all the tests? Or is there any restriction to that (i.e.: all the tests of the same package need to be executed together or something like that)?