最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Execution failed for task ‘:app:sonar’ when using Gradle Java Android Project - Stack Overflow

programmeradmin3浏览0评论

So i recently tried to create a Java Android project and add it to SonarCloud.

I did the following steps:

  • Created an anization on GitHub
  • Created repository
  • Created java android project (Empty Views Activity) using API 30 and Groovy DSL
  • Imported anization on
  • Added repository for analysis
  • Select free plan
  • Disabled automatic analysis
  • Added sonar token
  • Use GitHub CI as analysis method
  • Added build.yml and updated build.gradle.kts
  • Added gradlew permissions

When I try running the project locally, everything works fine. However, using the build script provided by SonarCloud itself using GitHub CI (see below), the CI crashes and the project does not get analyzed. I don't really know, where the issue is, since I only create a new Android Studio project and copy the build file from the SonarCloud instructions for GitHub CI

I have the following workflow build.yml file (generated by SonarCloud)

name: SonarQube
on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  build:
    name: Build and analyze
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
      - name: Set up JDK 17
        uses: actions/setup-java@v4
        with:
          java-version: 17
          distribution: 'zulu' # Alternative distribution options are available
      - name: Cache SonarQube packages
        uses: actions/cache@v4
        with:
          path: ~/.sonar/cache
          key: ${{ runner.os }}-sonar
          restore-keys: ${{ runner.os }}-sonar
      - name: Cache Gradle packages
        uses: actions/cache@v4
        with:
          path: ~/.gradle/caches
          key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
          restore-keys: ${{ runner.os }}-gradle
      - name: Build and analyze
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        run: ./gradlew build sonar --info --stacktrace

My build.gradle looks like the following (I also added the SonarCloud related changes)

plugins {
    alias(libs.plugins.android.application)
    id ".sonarqube" version "6.0.1.5171"
}

sonar {
    properties {
        property "sonar.projectKey", "SE-II-group-new_testing-2"
        property "sonaranization", "se-ii-group-new"
        property "sonar.host.url", ";
    }
}

android {
    namespace 'testing_2'
    compileSdk 35

    defaultConfig {
        applicationId "testing_2"
        minSdk 30
        targetSdk 35
        versionCode 1
        versionName "1.0"

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

dependencies {

    implementation libs.appcompat
    implementation libs.material
    implementation libs.activity
    implementation libs.constraintlayout
    testImplementation libs.junit
    androidTestImplementation libs.ext.junit
    androidTestImplementation libs.espresso.core
}

My dependencies (also updated to the latest version which still does not work). The depencies were automatically added when creating my project using Android Studio.

[versions]
agp = "8.9.0"
junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
appcompat = "1.7.0"
material = "1.12.0"
activity = "1.10.1"
constraintlayout = "2.2.1"

[libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" }
ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }

GitHub CI Action Error Log

> Task :app:sonar FAILED

AAPT2 aapt2-8.9.0-12782657-linux Daemon #0: shutdown
FAILURE: Build failed with an exception.
AAPT2 aapt2-8.9.0-12782657-linux Daemon #1: shutdown

* What went wrong:
Execution failed for task ':app:sonar'.
> '.apachemonspress.archivers.tar.TarArchiveEntry .apachemonspress.archivers.tar.TarArchiveInputStream.getNextEntry()'

* Try:
> Run with --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at .
Android Lint: Disposing Uast application environment in lint classloader [31.9.0_false]
[Incubating] Problems report is available at: file:///home/runner/work/testing-2/testing-2/build/reports/problems/problems-report.html

* Exception is:
.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:sonar'.
Caused by: java.lang.NoSuchMethodError: '.apachemonspress.archivers.tar.TarArchiveEntry .apachemonspress.archivers.tar.TarArchiveInputStream.getNextEntry()'

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to .11.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
86 actionable tasks: 86 executed

My project uses gradle 8.11.1.

GitHub repository:
SonarCloud:

I am a bit confused, why it does not work, since the same step by step instruction worked a year ago. Would be great if somebody can help!

I have the same issue when using Kotlin with KotlinDSL

发布评论

评论列表(0)

  1. 暂无评论