Sonar version : org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.1
FAILURE: Build failed with an exception.
What went wrong:
com/android/build/gradle/api/BaseVariant > com.android.build.gradle.api.BaseVariant
Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Exception is:
java.lang.NoClassDefFoundError: com/android/build/gradle/api/BaseVariant
at org.sonarqube.gradle.SonarQubePlugin.lambda$null$12(SonarQubePlugin.java:130)
at org.sonarqube.gradle.SonarQubePlugin.lambda$getAndroidCompileTasks$13(SonarQubePlugin.java:145)
at org.gradle.util.GUtil.uncheckedCall(GUtil.java:425)
Caused by: java.lang.ClassNotFoundException: com.android.build.gradle.api.BaseVariant
... 120 more
Get more help at https://help.gradle.org
BUILD FAILED in 489ms
The objective is to put the whole Sonar gradle block in a external gradle file (named here sonar.gradle) and to only add apply from: "sonar.gradle" to the build.gradle.
The plugin {} syntax cannot be used in external gradle file unfortunately. Gradle documentation states that “Future versions of Gradle will remove this restriction”.
The old syntax has to be used for now. As for why we have to use the fully qualified class name org.sonarqube.gradle.SonarQubePlugin instead of the string id "org.sonarqube", this is also a restriction in external gradle file.
Having tried to put the Sonar gradle block in the build.gradle, it works. The issue comes when we try to move the block in an external file.
Thanks for the answer. In this example, it is still required to add plugin { id 'org.sonarqube' version '3.0' } in the root build.gradle. Is there a way to move it as well in sonar.gradle where my full Sonar configuration is?
I’ve been able to apply other gradle plugins in external gradle files with the syntax described in the issue. I’m not sure what’s different with Sonar plugin that triggers the exception.
Thank you for the clarification. I see now what you mean. It doesn’t seem doable. You will probably get better traction from the https://discuss.gradle.org/ forum.