SonarCloud not compatible with Gradle 7

I am trying to upgrade to Gradle 7 and am experiencing the following error with SonarCloud:

Task :sonarqube FAILED
WARNING:API ‘variant.getJavaCompile()’ is obsolete and has been replaced with ‘variant.getJavaCompileProvider()’.
It will be removed in version 7.0 of the Android Gradle plugin.
For more information, see https://d..com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getJavaCompile(), use -P
.debug.obsoleteApi=true on the command line to display more information.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use ‘–warning-mode all’ to show the individual deprecation warnings.
See Command-Line Interface
451 actionable tasks: 451 executed

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem was found with the configuration of task ‘:sonarqube’ (type ‘SonarQubeTask’).
    • Type ‘org.sonarqube.gradle.SonarQubeTask’ property ‘pluginVersion’ is private and annotated with @Internal.

      Reason: Annotations on private getters are ignored.

      Possible solutions:

      1. Make the getter public.
      2. Annotate the public version of the getter.

      Please refer to Dealing with validation problems for more details about this problem.

This looks to be something that isn’t supported yet in SonarCloud, can someone please help me with a workaround or an ETA on when the next patch will be released for this bug?

Thanks!

Hello @lhope,

Thanks for your message. Could you please share your build.gradle/build.bradle.kts file, so I can have a look to understand why you see the issue.

And another point: Is the migration successful without sonarqube plugin?

Regards,
Margarita

I have the same problem.
locally on 3 different computers with three Android Studios everything works, on the server the Build crashes

before upgrading gradle version 4 to 7 everything worked. the same code if I bring it back to 4 works

 
File Build.gradle (module)


apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-kapt'

android {

    signingConfigs {
        MyGenapiSign {
            storeFile file('myfile-android.jks')
            storePassword 'xxyx!xxYxr'
            keyPassword 'xxyx!xxYxr1234'
            keyAlias 'MyFile'
        }
    }
    compileSdkVersion 30

    defaultConfig {
        applicationId "fr.my.my"
        minSdkVersion 28
        targetSdkVersion 30
        versionCode 17
        versionName "1.0"


        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        signingConfig signingConfigs.MyGenapiSign
    }

    buildTypes {
        debug {
            debuggable true

            buildConfigField  "String", "BUILD_VARIANT",  "\"debug\""

            resValue "string", "SSO_PROD", SSO_PROD
            resValue "string", "SSO_DEV", SSO_DEV
 

        }

        release {
            debuggable true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.MyGenapiSign

            buildConfigField  "String", "BUILD_VARIANT",  "\"release\""

            resValue "string", "SSO_PROD", SSO_PROD
            resValue "string", "SSO_DEV", SSO_DEV

           
        }
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    ndkVersion '22.0.7026061'

    lintOptions {
        abortOnError false
    }

    }

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
   // implementation "org.jetbrains.kotlin:kotlin-stdlib:1.4.10"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
    implementation 'com.google.firebase:firebase-analytics:19.0.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'

    // Declare the dependencies for the Crashlytics and Analytics libraries
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation platform('com.google.firebase:firebase-bom:26.1.0')
    implementation 'com.google.firebase:firebase-crashlytics-ktx'

    implementation 'com.google.firebase:firebase-analytics-ktx'

    implementation 'androidx.wear:wear:1.1.0'
    implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
    implementation 'com.google.firebase:firebase-crashlytics:18.2.1'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'org.jetbrains.anko:anko-common:0.9'
    //noinspection GradleCompatible
    implementation 'com.android.support:cardview-v7:28.0.0'

    implementation 'androidx.biometric:biometric:1.2.0-alpha03'
    compileOnly 'com.google.android.wearable:wearable:2.8.1'

    implementation 'com.google.android.gms:play-services-basement:17.6.0'

   // implementation platform('com.google.firebase:firebase-bom:25.12.0')

    ///ROOM
    def room_version = "2.3.0"

    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

    // JWT Decode
    implementation 'com.auth0.android:jwtdecode:2.0.0'

    // Licensing
    implementation 'com.auth0:java-jwt:3.13.0'

    implementation 'com.google.code.gson:gson:2.8.6'

    //Circleimageview
    implementation 'de.hdodenhof:circleimageview:3.0.0'

    //Chrome Custom Tabs
    //noinspection GradleCompatible
    implementation 'com.android.support:customtabs:28.0.0'

    implementation "androidx.browser:browser:1.3.0"
    //noinspection GradleCompatible
    implementation 'com.android.support:support-v4:28.0.0'

    //lifecycle
    implementation "android.arch.lifecycle:extensions:1.1.1"

    // Declare the dependency for the Performance Monitoring library
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-perf-ktx'


}


File Build.gradle (project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.5.20'
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.8'

        // Add the dependency for the Performance Monitoring plugin
        classpath 'com.google.firebase:perf-plugin:1.4.0'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
// Performance Monitoring plugin

    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


Task :sonarqube FAILED
WARNING:API ‘variant.getJavaCompile()’ is obsolete and has been replaced with ‘variant.getJavaCompileProvider()’.
It will be removed in version 7.0 of the Android Gradle plugin.
For more information, see Task Configuration Avoidance.
To determine what is calling variant.getJavaCompile(), use -Pandroid.debug.obsoleteApi=true on the command line to display more information.

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem was found with the configuration of task ‘:sonarqube’ (type ‘SonarQubeTask’).
    • Type ‘org.sonarqube.gradle.SonarQubeTask’ property ‘pluginVersion’ is private and annotated with @Internal.

      Reason: Annotations on private getters are ignored.

      Possible solutions:

      1. Make the getter public.
      2. Annotate the public version of the getter.

Hello @HydraRock,

Thanks for your message. I don’t see any reference to the sonarqube plugin in your build configuration. Could you please provide some more information like full log of the analysis and the right build configuration.

And what do you mean by locally is ok and on server build crashes? Is it your CI? Maybe it will be nice to share your CI configuration too, so I can have a look and probably help.

Regards,
Margarita

I am seeing the same issue with Gradle 7.2 and “org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3”

Thanks for your message and could you, please, provide a minimum reproducer, so I can investigate the problem further?

Regards,
Margarita

@lhope @HydraRock @Claus_Holst

According to the logs provided I can make a conclusion that you’re using sonarqube plugin of version <2.7 where there is an @Internal annotation on a private getter which is incompatible with the Gradle 7. This was already fixed here.

Please, make sure you’re using the latest version of sonarqube gradle plugin (3.3). The issue should disappear.

If you still can reproduce the issue, please open another thread a provide a proper reproducer, detailed logs and configuration.

Regards,
Margarita

1 Like