green-code-initiative / ecoCode-android

Reduce the environmental footprint of your Java-based Android apps with SonarQube
https://ecocode.io
GNU General Public License v3.0
54 stars 17 forks source link

Incompatibility with Groovy (community) plugin #84

Closed thomasgl-orange closed 7 months ago

thomasgl-orange commented 7 months ago

Describe the bug

It seems that because of the way this plugin includes a rebranded copy of https://github.com/Inform-Software/sonar-groovy (for handling Gradle files), it can't be deployed together with the original. Apparently, they both compete on declaration of the sonar.groovy.file.suffixes settings property.

It is unfortunate since this plugin doesn't provide the functionalities of the original Groovy plugin (no rules or profile for the actual Groovy language, only a few Gradle specific rules).

To Reproduce Steps to reproduce the behavior:

  1. install both sonar-groovy plugin and ecocode-android
  2. start SonarQube (10.2 EE in our case)
  3. See error:
2023.11.29 15:42:02 ERROR web[][o.s.s.p.Platform] Background initialization failed. Stopping SonarQube
java.lang.IllegalStateException: Fail to load plugin Groovy [groovy]
    at org.sonar.server.plugins.ServerExtensionInstaller.installExtensions(ServerExtensionInstaller.java:81)
    at org.sonar.server.platform.platformlevel.PlatformLevel4.start(PlatformLevel4.java:668)
    at org.sonar.server.platform.PlatformImpl.start(PlatformImpl.java:214)
    at org.sonar.server.platform.PlatformImpl.startLevel34Containers(PlatformImpl.java:194)
    at org.sonar.server.platform.PlatformImpl$AutoStarterRunnable.runIfNotAborted(PlatformImpl.java:362)
    at org.sonar.server.platform.PlatformImpl$1.doRun(PlatformImpl.java:113)
    at org.sonar.server.platform.PlatformImpl$AutoStarterRunnable.run(PlatformImpl.java:346)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@12bcd0c0-org.sonar.api.config.PropertyDefinition-sonar.groovy.file.suffixes' defined in null: Cannot register bean definition [Generic bean: class [org.sonar.api.config.PropertyDefinition]; scope=singleton; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'jdk.internal.loader.ClassLoaders$AppClassLoader@12bcd0c0-org.sonar.api.config.PropertyDefinition-sonar.groovy.file.suffixes': There is already [Generic bean: class [org.sonar.api.config.PropertyDefinition]; scope=singleton; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:1006)
    at org.springframework.context.support.GenericApplicationContext.registerBeanDefinition(GenericApplicationContext.java:342)
    at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.registerBeanDefinition(BeanDefinitionReaderUtils.java:164)
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.doRegisterBean(AnnotatedBeanDefinitionReader.java:285)
    at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:233)
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.registerBean(AnnotationConfigApplicationContext.java:198)
    at org.sonar.core.platform.SpringComponentContainer.registerInstance(SpringComponentContainer.java:126)
    at org.sonar.core.platform.SpringComponentContainer.addExtension(SpringComponentContainer.java:142)
    at org.sonar.core.platform.SpringComponentContainer.addExtension(SpringComponentContainer.java:236)
    at org.sonar.core.platform.SpringComponentContainer.addExtension(SpringComponentContainer.java:41)
    at org.sonar.server.plugins.ServerExtensionInstaller.installExtension(ServerExtensionInstaller.java:89)
    at org.sonar.server.plugins.ServerExtensionInstaller.installExtensions(ServerExtensionInstaller.java:73)
    ... 7 common frames omitted
2023.11.29 15:42:02 INFO  web[][o.s.p.ProcessEntryPoint] Hard stopping process

The relevant bit is:

'jdk.internal.loader.ClassLoaders$AppClassLoader@12bcd0c0-org.sonar.api.config.PropertyDefinition-sonar.groovy.file.suffixes': There is already [Generic bean: class [...] bound

Expected behavior

Not crash... It's probably a matter of renaming a few more things, at least this sonar.groovy.file.suffixes property key. Maybe also Gradle files could be handled as a specific language, leaving Groovy files (grvy) alone?

Or at least, if incompatibility won't be solved, maybe document the issue in the project README?

thomasgl-orange commented 7 months ago

oops, obvious duplicate of #83 (two colleagues taking the same initiative at the same time...)