I am getting the following issue while starting sonarqube with custom java maven plugin.
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jdk.internal.loader.ClassLoaders$AppClassLoader@5ffd2b27-org.sonar.server.rule.RegisterRules’: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/sonar/api/internal/SonarRuntimeImpl
As per the issue log, the issue is due to following line of code:
The classes located in the package org.sonar.api.internal are not accessible to plugins during runtime and can only be used in testing scenarios.
I’m not sure what your objective is, but you don’t need to create a SonarRuntime instance manually. Instead, you can obtain a SonarRuntime instance through the plugin context. Here’s an example:
public class MyPlugin implements Plugin {
@Override
public void define(Plugin.Context context) {
SonarRuntime runtime = context.getRuntime();
I tried as you suggested for SonarRuntime object, but there is similar issue:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jdk.internal.loader.ClassLoaders$AppClassLoader@5ffd2b27-org.sonar.server.rule.RegisterRules’: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/sonarsource/analyzer/commons/RuleMetadataLoader
As per the log, the following code is giving the issue:
RuleMetadataLoader ruleMetadataLoader = new RuleMetadataLoader(RULES_BASE_PATH, runtime);