【问题标题】:Sonarqube running on older gradle version in gitlabSonarqube 在 gitlab 中的旧 gradle 版本上运行
【发布时间】:2021-12-10 21:42:51
【问题描述】:

我有一个运行良好的 android 项目,但是当我尝试从 CI/CD 运行 sonarqube-check 时,它显示较低的 gradle 错误我的项目已经在最新的 gradle 上运行 7.0.3

sonarqube 已经在 gitlab 中设置好了

项目级分级

// 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
}

应用级分级

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

我正在尝试从 CI/CD 管道检查

我得到这样的回应

添加 ylm 后显示此警告

请告诉我有什么问题

任何建议都将受到高度赞赏。

【问题讨论】:

  • 您能否分享您的 GitLab CI yml 文件中的相关部分;)我想我知道这个问题,但我想确定一下;)
  • @SimonSchrottner yml 文件已添加
  • 我同时写了一个答案,缺少上下文,但它本身的消息和上下文是相同的

标签: android gitlab sonarqube


【解决方案1】:

我假设您使用the official gradle template 作为起点,这也是问题所在。

他们使用的 docker 镜像image: gradle:alpine 已有两年历史,此后一直没有更新。这意味着它包含过时的 gradle 版本。

我只能推荐使用像eclipse-temurin这样的默认java镜像并使用Gradle Wrapper——这样你只需要确保你有正确的java版本,不需要关心gradle。有关 gradle Wrapper 的更多信息,请参阅https://docs.gradle.org/current/userguide/gradle_wrapper.html

build:
  stage: build
  script: ./gradlew --build-cache assemble
  image: eclipse-temurin:<java-version>

【讨论】:

  • 我应该把这段代码放在哪里?
  • 请检查我添加了显示警告的屏幕截图
  • 这是一个完整的工作作为示例,而不是您可以使用的复制粘贴
  • 我没有使用 gradle:alpine 默认我使用的是 gradle:jre11-slim 所以这对我来说不是问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-01
  • 2017-06-26
相关资源
最近更新 更多