SonarSource / sonar-scanning-examples

Shows how to use the Scanners
GNU Lesser General Public License v3.0
886 stars 2.19k forks source link

Sonarqube running on older gradle version in gitlab #123

Closed Miteshmakwana73 closed 2 years ago

Miteshmakwana73 commented 2 years ago

I have one android project which is running perfectly but when i try to run sonarqube-check from CI/CD it's showing lower gradle error my project is already running on latest gradle 7.0.3

sonarqube is already setup in gitlab

Project level gradle


// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven {
            url 'https://sdk.squareup.com/public/android'
        }
    }
}

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

app-level gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id "org.sonarqube" version "3.3"
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.sonarqube"
        minSdk 23
        targetSdk 31
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }
    buildFeatures {
        viewBinding true
    }

}
sonarqube {
    tasks.sonarqube.dependsOn build
    properties {
        property "sonar.projectKey", "root_sonarqube_android_xyz-"
        property "sonar.sourceEncoding", "UTF-8"
        property "sonar.sources", "src"
    }
}
dependencies {
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

.gitlab-ci.yml

sonarqube-check:
  tags:
    - runner
  image: gradle:jre11-slim
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: gradle sonarqube
  allow_failure: true
  when: manual
  only:
    - dev_mitesh # or the name of your main branch

i am trying to check from CI/CD pipelines k7ATe (1)

i am getting something like this in response

Capture

Please suggest me what is wrong

Any suggestion would be highly appreciated.

sylvain-combe-sonarsource commented 2 years ago

Help on scanning errors on your own projects is provided on SonarSource community, not here.