For several days I have been trying without success to deploy my test plugin on sonarqube.
My problem is at the manifest.mf level
My environment for plugin development :
IntelliJ IDEA Community Edition 2024.2.3 on linux
I tried to generate it using the pom.xml without success and when I manually enter the manifest.mf I always get the same error:
> Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@1941a8ff-org.sonar.server.plugins.ServerPluginManager': Initialization of bean failed; nested exception is java.lang.NullPointerException: Plugin key is missing from manifest
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@1941a8ff-org.sonar.server.plugins.ServerPluginManager': Initialization of bean failed; nested exception is java.lang.NullPointerException: Plugin key is missing from manifest
error from daemon in stream: Error grabbing logs: invalid character '\x00' looking for beginning of value
However, as you can see in the manifest the plugin key is present
Does one of you have an idea or solution to offer me?
If you have examples of a working pom.xml I am also interested.
Thanking you in advance
Hello Felipe ,
Thank you for your response. I actually started by doing that. However, the pom does not generate any manifest in this specific case and I don’t understand why…
I don’t have any information on the generation of the jar either:
$ mvn clean package
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
[INFO] Scanning for projects...
[INFO]
[INFO] --------< org.sonarqube.customrules:sonarqube-js-custom-rules >---------
[INFO] Building sonarqube-js-custom-rules 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ sonarqube-js-custom-rules ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ sonarqube-js-custom-rules ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.13.0:compile (default-compile) @ sonarqube-js-custom-rules ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 7 source files with javac [debug release 11] to target/classes
[INFO] /home/xxx/Desktop/intellij/sonarqube-js-custom-rules/src/main/java/org/sonarqube/customrules/CustomRulesDefinition.java: /home/xxx/Desktop/intellij/sonarqube-js-custom-rules/src/main/java/org/sonarqube/customrules/CustomRulesDefinition.java uses or overrides a deprecated API.
[INFO] /home/xxx/Desktop/intellij/sonarqube-js-custom-rules/src/main/java/org/sonarqube/customrules/CustomRulesDefinition.java: Recompile with -Xlint:deprecation for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ sonarqube-js-custom-rules ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.13.0:testCompile (default-testCompile) @ sonarqube-js-custom-rules ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ sonarqube-js-custom-rules ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ sonarqube-js-custom-rules ---
[INFO] Building jar: /home/xxx/Desktop/intellij/sonarqube-js-custom-rules/target/sonarqube-js-custom-rules-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.530 s
[INFO] Finished at: 2024-10-12T18:36:04+02:00
[INFO] ------------------------------------------------------------------------
And I also tried this command which generates a manifest for me but without success.This produces the file but the error persists when restarting the docker container.
jar xf target/sonarqube-js-custom-rules-1.0-SNAPSHOT.jar META-INF/MANIFEST.MF
cat META-INF/MANIFEST.MF
After taking a closer look, I’d advise against spending time on creating this plugin. The ability to write custom JavaScript rules in Java was discontinued in SonarQube 8.9.
No matter the effort or dependencies you use, SonarQube won’t load the custom rules as expected.
Anyway, if you still want to understand what’s the problem with your pom.xml file:
it should declare <packaging>sonar-plugin</packaging>
the maven-jar-plugin should be removed
sonar-plugin-api dependency must be declared with scope “provided”
sonar-packaging-maven-plugin must configured with the required properties pluginKey, pluginClass and pluginDescription.
Felipe,
Indeed, from the start it did not work because of forgetting the declaration of<packaging>sonar-plugin</packaging>… Thanks.
Is ESlint the only one that could allow me to create custom rules ?
In any case, thank you for your very valuable help