Class not found error; CustomRuleRepository; after installing custom javascript rule jar


(John Collins) #1

I created a custom javascript rules jar based on this:

Unit tests pass.
Installed jar in …/extentions/plugins
sonarQube would not start.
Got the following error:

2019.03.13 09:56:36 ERROR web[][o.s.s.p.Platform] Background initialization failed. Stopping SonarQube
java.lang.IllegalStateException: Fail to load plugin JavaScript My Rules [jscustom]
        at org.sonar.server.plugins.ServerExtensionInstaller.installExtensions(ServerExtensionInstaller.java:88)
        at org.sonar.server.platform.platformlevel.PlatformLevel4.start(PlatformLevel4.java:582)
        at org.sonar.server.platform.Platform.start(Platform.java:211)
        at org.sonar.server.platform.Platform.startLevel34Containers(Platform.java:185)
        at org.sonar.server.platform.Platform.access$500(Platform.java:46)
        at org.sonar.server.platform.Platform$1.lambda$doRun$0(Platform.java:119)
        at org.sonar.server.platform.Platform$AutoStarterRunnable.runIfNotAborted(Platform.java:371)
        at org.sonar.server.platform.Platform$1.doRun(Platform.java:119)
        at org.sonar.server.platform.Platform$AutoStarterRunnable.run(Platform.java:355)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: org/sonar/plugins/javascript/api/CustomRuleRepository
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
        at org.sonar.classloader.ClassRealm.loadClassFromSelf(ClassRealm.java:125)
        at org.sonar.classloader.ParentFirstStrategy.loadClass(ParentFirstStrategy.java:37)
        at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:87)
        at org.sonar.classloader.ClassRealm.loadClass(ClassRealm.java:76)
        at edu.udel.javascript.JavaScriptMyRulesPlugin.define(JavaScriptMyRulesPlugin.java:31)
        at 


org.sonar.server.plugins.ServerExtensionInstaller.installExtensions(ServerExtensionInstaller.java:78)
        ... 9 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.sonar.plugins.javascript.api.CustomRuleRepository
        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)
        ... 24 common frames omitted
2019.03.13 09:56:36 INFO  web[][o.s.p.StopWatcher] Stopping process

I don’t know exactly what the 2nd and 3rd bullet point in the instructions means:

  • Attach this plugin to SonarJS through the pom.xml
  • add the dependency to SonarJS

Which pom file is “the” pom.xml? My plugin’s? SonarJS’s? SonarQube’s?
Does SonarJS depend on my plugin or does my plugin depend on SonarJS? What specific syntax should be used?

Any help is appreciated. I’ve been googling in circles for a few hours.


(Michael Gumowski) #2

Hey John,

I’m pretty sure you don’t need to update the SonarJS plugin itself, nor SonarQube. So the pom.xml to update would be the one from your custom plugin.

In particular, check that the SonarJS version you are using to build your custom-rule plugin is matching the one installed on your SonarQube instance: https://github.com/SonarSource/sonar-custom-rules-examples/blob/master/javascript-custom-rules/pom.xml#L18

From your logs, it seems that there is no CustomRuleRepository class available in your SonarQube instance… and you need it from your JavaScriptCustomRulesDefinition class.

I just tried with latest release of SonarJS (5.0.0.6962) and the same custom plugin repository, and it seems to work quite well on my SonarQube instance.

Hope this helps,
Michael


(John Collins) #3

Michael, Thanks for the reply and the info. I’m in the process of getting SonarJS updated to the latest version and I’ll re-try my plugin.