jborgers / sonar-pmd

☕️ PMD Plugin for SonarQube
https://redirect.sonarsource.com/plugins/pmd.html
GNU Lesser General Public License v3.0
254 stars 154 forks source link

Make sonar-pmd compatible with SonarQube 10.4 'DownloadOnlyWhenRequired' feature #421

Closed ganncamp closed 2 months ago

ganncamp commented 5 months ago

SonarQube 10.4 will come with a feature to only download plugins when they are required. When there are files corresponding to the language handled by the plugin, the plugin will be downloaded, otherwise, the plugin won't be downloaded. This is great to save network bandwidth and speed up the bootstrap of the scans. This feature will be disabled by default to let the time to plugin maintainers to adjust their plugin. It will be activated by default with SonarQube 10.5

For plugins that have a dependency on a base analyzer provided by default with SonarQube, an additional property is required to be added to the MANIFEST of the plugin. By doing so you will avoid being in this situation:

sonar-pmd is downloaded because it doesn't support the new property so it is downloaded from the server at each scan sonar-java is not downloaded because there are no .java files in the repo to scan a NoClassDefFoundError is thrown In order to avoid that you need to:

upgrade sonar-packaging-maven-plugin to https://github.com/SonarSource/sonar-packaging-maven-plugin/releases/tag/1.22.0.705 add java

agigleux commented 3 months ago

Hey,

SonarQube 10.5 will have the feature to only download plugins when they are required, activated by default. It means if users move to 10.5 and still use the PMD Plugin, all analyses will start to fail with an error looking like this:

09:40:47.151 ERROR: Caused by: Error creating bean with name 'ClassRealm{pmd}-org.sonar.plugins.pmd.PmdSensor': Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ClassRealm{pmd}-org.sonar.plugins.pmd.PmdExecutor': Resolution of declared constructors on bean Class [org.sonar.plugins.pmd.PmdExecutor] from ClassLoader [ClassRealm{pmd}] failed; nested exception is java.lang.NoClassDefFoundError: org/sonar/plugins/java/api/JavaResourceLocator
09:40:47.151 ERROR: Caused by: Error creating bean with name 'ClassRealm{pmd}-org.sonar.plugins.pmd.PmdExecutor': Resolution of declared constructors on bean Class [org.sonar.plugins.pmd.PmdExecutor] from ClassLoader [ClassRealm{pmd}] failed; nested exception is java.lang.NoClassDefFoundError: org/sonar/plugins/java/api/JavaResourceLocator

The only workaround will be to deactivate the feature in the UI (search for the sonar.plugins.downloadOnlyRequired property).

jborgers commented 2 months ago

3.5.1-beta pre-release is published to try-out.

jborgers commented 2 months ago

We just released 3.5.1

jborgers commented 2 months ago

Works in 10.5