Getting error while running sonar-scanner in gitlab CI/CD pipeline

So basically i am using sonarqube for my react project. while running sonar-scanner in my local environment , it is running successfully but when I run it in the gitlab CI pipeline it is failing with the error mentioned below. can someone help please?

this is my CI pipeline config:

sonarqube-check:
  stage: sonarqube-check
  image: 
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script: 
    - sonar-scanner
  allow_failure: true

Error logs:

Running with gitlab-runner 13.8.0 on EC2 runner -----
Preparing the "docker" executor 30:04
Using Docker executor with image sonarsource/sonar-scanner-cli:latest ...
Authenticating with credentials from /root/.docker/config.json
Pulling docker image sonarsource/sonar-scanner-cli:latest ...


SonarScanner 5.0.1.3006
Java 17.0.11 Alpine (64-bit)
Linux 4.14.214-118.339.amzn1.x86_64 amd64
User cache: /builds/webpanels/nexs-ui/.sonar/cache
Analyzing on SonarQube server 10.3.0.82913

ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: Unable to load components interface org.sonar.api.batch.sensor.Sensor at org.sonar.core.platform.SpringComponentContainer.getComponentsByType(SpringComponentContainer.java:169)

at org.sonar.scanner.bootstrap.AbstractExtensionDictionary.completeScannerExtensions(AbstractExtensionDictionary.java:82)

at org.sonar.scanner.bootstrap.AbstractExtensionDictionary.getExtensions(AbstractExtensionDictionary.java:77)

at org.sonar.scanner.bootstrap.AbstractExtensionDictionary.getFilteredExtensions(AbstractExtensionDictionary.java:67)

at org.sonar.scanner.sensor.ModuleSensorExtensionDictionary.selectSensors(ModuleSensorExtensionDictionary.java:47)

at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$0(ModuleSensorsExecutor.java:54)

at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:79)

at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:54)

at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)

at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:201)

at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:180)

at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:398)

at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:394)

at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:363)

at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:201)

at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:180)

at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:139)

at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:201)

at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:180)

at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:71)

at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:65)

at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.base/java.lang.reflect.Method.invoke(Method.java:568)

at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)

at jdk.proxy1/jdk.proxy1.$Proxy0.execute(Unknown Source)

at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)

at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)

at org.sonarsource.scanner.cli.Main.execute(Main.java:126)

at org.sonarsource.scanner.cli.Main.execute(Main.java:81)

at org.sonarsource.scanner.cli.Main.main(Main.java:62)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ClassRealm{securitypythonfrontend}-com.sonar.security.frontend.python.A': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.sonar.security.frontend.python.A] from ClassLoader [ClassRealm{securitypythonfrontend}]

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:289)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1302)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1219)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:673)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:661)

at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1302)

at org.sonar.core.platform.SpringComponentContainer.getComponentsByType(SpringComponentContainer.java:167)

... 32 more

Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.sonar.security.frontend.python.A] from ClassLoader [ClassRealm{securitypythonfrontend}]

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485)

at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321)

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267)

... 44 more

Caused by: java.lang.NoClassDefFoundError: org/sonar/sslr/grammar/GrammarRuleKey

at java.base/java.lang.Class.getDeclaredMethods0(Native Method)

at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402)

at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504)

at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467)

... 46 more

Caused by: java.lang.ClassNotFoundException: org.sonar.sslr.grammar.GrammarRuleKey

at org.sonar.classloader.ParentFirstStrategy.loadClass(ParentFirstStrategy.java:39)

at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:87)

at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:76)

... 50 more

ERROR:

Hey there.

As just a troubleshooting step, can you change this to sonarsource/sonar-scanner-cli:5.0.1 and see if it changes the behavior?

1 Like

OMG, Colin you are a lifesaver.
yes, it worked.

Thank you so much, you don’t know how much time I have wasted on this.

Hey there.

You should be able to switch back to the latest version if you clear your cache folder.