Gradle scanner 7.3.0 sets invalid Java binaries for AGP 9.2

We hit this while upgrading an Android project to both:

  • Android Gradle Plugin 9.2.0
  • SonarQube Gradle plugin 7.3.0.8198

The previous CI baseline, before this upgrade stack, used SonarQube Gradle plugin 7.2.3.7755 and completed successfully.

What worked before

Before this upgrade stack, the Sonar task completed successfully with:

  • SonarQube Gradle plugin 7.2.3.7755
  • sonar.gradle.skipCompile=true
  • CI command: ./gradlew sonar -Dsonar.token=... -Pandroid.newDsl=false

That baseline still logged Java analyzer warnings about unresolved Android/JDK types, but they were non-fatal and the build ended with BUILD SUCCESSFUL.

What fails now

After upgrading to AGP 9.2.0 and SonarQube Gradle plugin 7.3.0.8198, the same CI command fails:

Execution failed for task ':sonar'.
> org.sonar.java.AnalysisException: Your project contains .java files, please provide compiled classes with sonar.java.binaries property, or exclude them from the analysis with sonar.exclusions property.

The project contains Java files in Android library modules, including:

  • regular Java sources under src/main/java/...
  • generated Java sources registered with variant.sources.java?.addStaticSourceDirectory(...)

Possible root cause

From the scanner source, 7.3.0.8198 added a new AGP 9 code path in AndroidConfig.

That path appears to compute sonar.java.binaries using this hard-coded directory shape:

build/intermediates/javac/<componentName>/classes

For AGP 9.2.0, the actual JavaCompile output directory is:

build/intermediates/javac/<variant>/compile<Variant>JavaWithJavac/classes

For example:

build/intermediates/javac/debug/compileDebugJavaWithJavac/classes

Because the scanner later filters non-existing path properties before analysis, the guessed sonar.java.binaries path is removed. The scanner then sees Java source files but no valid sonar.java.binaries, which triggers the fatal Java analyzer error above.

Suggested direction

Instead of synthesizing the class output path from the component name, the AGP 9 path should use the matched JavaCompile task’s actual destinationDirectory, similar to the legacy AGP path that used variant.getJavaCompileProvider().getOrNull().getDestinationDirectory().

This avoids depending on AGP internal output directory layout and should be more robust for custom Gradle/AGP behavior.

Hi,

Thanks for this report.

I believe the tickets created in this thread cover the problem you’re seeing. Do you agree?

 
Thx,
Ann

It seems like you may have linked your comment to the original thread. Could you please check your original reply?

This PR is associated with the fix for this issue: Fix AGP 9 Java binaries resolution by bc-lee · Pull Request #501 · SonarSource/sonar-scanner-gradle · GitHub

Please take a look. Thanks.

Hi,

Sorry about that!

Try this one:

 
Ann

Hi,

We are currently experiencing the same generated file issue and are waiting for the PR to be merged and rolled out with the new version.

Do you already have an estimated timeline for the next Sonar plugin release? This would help us plan our update accordingly.

Thanks,

Veli

Hi @vakdeniz,

Welcome to the community!

Unfortunately, I don’t have a timeline for you.

 
Ann

Hi @bc-lee, @vakdeniz,

We have just released a new version of the scanner that should address the issue reported here.