Execution failed for task ':app:sonar'

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

I did the following steps:

  • Created an organization on GitHub
  • Created repository
  • Created java android project (Empty Views Activity) using API 30 and Groovy DSL
  • Imported organization on SonarQube Cloud
  • 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 "org.sonarqube" version "6.0.1.5171"
}

sonar {
    properties {
        property "sonar.projectKey", "SE-II-group-new_testing-2"
        property "sonar.organization", "se-ii-group-new"
        property "sonar.host.url", "https://sonarcloud.io"
    }
}

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'.
> 'org.apache.commons.compress.archivers.tar.TarArchiveEntry org.apache.commons.compress.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 https://help.gradle.org.
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:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:sonar'.
Caused by: java.lang.NoSuchMethodError: 'org.apache.commons.compress.archivers.tar.TarArchiveEntry org.apache.commons.compress.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 https://docs.gradle.org/8.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: GitHub - SE-II-group-new/testing-2
SonarCloud: SonarQube Cloud

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

Have you managed to solve this?
I’m having the same issue on 10.7 community build + sonarqube gradle plugin 6.0.1.5171, but I have no clue where to even start because the error message is not informative.

Hey all.

I’m facing this issue, like @djamn, when I use GitHub Actions but not when I run the project locally.

I’ve flagged this for attention from our development teams.

1 Like

Same thing for me. Everything is fine when I run the gradle project on my mac. It’s failing only in my CI/CD pipeline (I use GitLab with Kubernetes executors)

Hi @djamn,

Thank you for reaching out and providing detailed information about your setup. For now, to resolve this, I recommend using version 5.1 of the Sonar Gradle scanner. I have just tested and it should work without causing the issue you’re experiencing.

From the log, I think the problem might be due to a dependency conflict between the latest scanner version and Android. I will continue to investigate.

1 Like

Hi, really appreciate your quick work around and that you are looking into it!

The workaround works fine, I now use the following version:

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

Thank you for your help!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.