Failing to resolve dependency, but only when sonar is running

Must-share information (formatted with Markdown):

  • which versions are you using: sonarqube-gradle-plugin:3.4.0.2513
  • what are you trying to achieve: I am trying to get sonarqube working via CI
  • what have you tried so far to achieve this

I have setup my SONAR_TOKEN

I am configuring sonar via classpath:

org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.4.0.2513
private fun Project.configureSonar() {
        pluginManager.apply(SonarQubePlugin::class.java)
        extensions.configure(SonarQubeExtension::class.java) {
            properties {
                property("sonar.projectKey", "company_android")
                property("sonar.organization", "company")
                property("sonar.host.url", "https://sonarcloud.io")
                property("sonar.userHome", "${buildDir}/.sonar")
            }
        }
    }

I found that I needed to add
property("sonar.userHome", "${buildDir}/.sonar") or it would fail with some race condition to resolve things. See Random Sub-projects Fail Analysis in Gradle Multi-projects Build

This actually fixed that issue for me.

When I run ./gradlew buildVariant, everything works and builds fine. But if I run ./gradlew buildVariant sonarqube, I get the error below:

> Task :messageCenter:sonarqube

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dataBindingMergeGenClassesVariantDebugAndroidTest'.
> Could not resolve all files for configuration ':app:variantrDebugAndroidTestCompileClasspath'.
   > Could not find com.datadoghq:dd-sdk-android:.
     Required by:
         project :app

That dependency 100% exists, it builds locally, and even in other CI jobs. But when running with sonarqube, it fails to resolve for some reason. Any ideas? I am wondering if it is somewhat related to the issue I saw earlier where I needed to add sonar.userHome to resolve some sort of race condition. This is a multi-module project with over 20 modules.

(Obfuscated some data with “company” and “variant” for privacy.

Hi Rohan,

Without seeing your Gradle config, it will be hard to help you out. Are your task dependencies all in order?