Missing Jar files when running Sonar Gradle Plugin with Java/Kotlin only modules

Hi, I’m trying to add Sonar Gradle plugin to our project.

We have a huge project with many modules applying Android Gradle Plugin but some of them only applying Java Gradle Plugin.

On the modules that only apply Java Gradle Plugin we get:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sonar'.
> Could not resolve all files for configuration ':app:debugCompileClasspath'.
   > Failed to transform module1.jar (project :common:module1) to match attributes {artifactType=android-classes-jar, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.environment=standard-jvm, org.gradle.jvm.version=21, org.gradle.libraryelements=jar, org.gradle.usage=java-api, org.jetbrains.kotlin.platform.type=jvm}.
      > Execution failed for IdentityTransform: /builds/mobile/common/module1/build/libs/module1.jar.
         > File/directory does not exist: /builds/mobile/common/module1/build/libs/module1.jar
   > Failed to transform module2.jar (project :common:module2) to match attributes {artifactType=android-classes-jar, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.environment=standard-jvm, org.gradle.jvm.version=21, org.gradle.libraryelements=jar, org.gradle.usage=java-api, org.jetbrains.kotlin.platform.type=jvm}.
      > Execution failed for IdentityTransform: /builds/mobile/common/module2/build/libs/module2.jar.
         > File/directory does not exist: /builds/mobile/common/module2/build/libs/module2.jar
...

(I obfuscated names of module1 and module2)

We have this in our Gradle convention plugin that we apply to Java/Kotlin only modules:

            rootProject.tasks.named("sonar") {
                dependsOn(tasks.named("jar"))
            }

Even though the “jar” tasks get executed before the “sonar” task, this doesn’t fix the issue.

Do you have any suggestion on how to make sure these jars are created before sonar task runs?

Thank you :folded_hands:

We are on Sonar Gradle Plugin 6.2.0.5505.

I noticed a similar issue happens for the testFixtures-full.jar files in the modules where we have test fixtures.

I found that:

  • runnning jar task creates jar outputs of Java only modules.
  • running createFullJarDebugTestFixtures (on Android) task creates jar outputs of test fixtures.

So we run the jar createFullJarDebugTestFixtures tasks before (in a separate command) running the sonar task in order to avoid this missing jar problem.

I wish Sonar Gradle Plugin would configure the necessary outputs and task dependencies so that we wouldn’t need to run its dependencies in advance like this.

If there is a better setup than this, I’m more than happy to hear :smiley:

Thank you,
Berkay.

Hi Berkay,

Analysis doesn’t require jar-ing, only compilation. We used to auto-run compile before analysis, but a lot of people ran into problems with that so we had to quit.

 
FWIW
Ann