Plugin key is missing from manifest

Hello community,

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

[image]

MANIFEST.MF.txt (284 Bytes)
pom.xml.txt (2.8 KB)

Hi,

Remoe the maven-jar-plugin from the pom.xml and all the MANIFEST.MF files and let the sonar-packaging-maven-plugin handle it.

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.

Here is a “fixed” pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.sonarqube.customrules</groupId>
  <artifactId>sonarqube-js-custom-rules</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>sonarqube-js-custom-rules</name>
  <packaging>sonar-plugin</packaging>

  <dependencies>
    <dependency>
      <groupId>org.sonarsource.api.plugin</groupId>
      <artifactId>sonar-plugin-api</artifactId>
      <version>10.6.0.2114</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.javascript</groupId>
      <artifactId>sonar-javascript-plugin</artifactId>
      <version>10.16.0.27621</version>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.javascript</groupId>
      <artifactId>javascript-checks</artifactId>
      <version>10.16.0.27621</version>
    </dependency>
    <dependency>
      <groupId>org.sonarsource.java</groupId>
      <artifactId>java-frontend</artifactId>
      <version>8.4.0.37032</version>
    </dependency>
    <dependency>
      <groupId>org.openjfx</groupId>
      <artifactId>javafx-controls</artifactId>
      <version>17.0.6</version>
    </dependency>
    <dependency>
      <groupId>org.openjfx</groupId>
      <artifactId>javafx-fxml</artifactId>
      <version>17.0.6</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
        <artifactId>sonar-packaging-maven-plugin</artifactId>
        <version>1.23.0.740</version>
        <extensions>true</extensions>
        <configuration>
          <pluginClass>org.sonarqube.customrules.CustomSonarQubePlugin</pluginClass>
          <pluginKey>my-rules</pluginKey>
          <pluginDescription>Any description here</pluginDescription>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.13.0</version>
        <configuration>
          <source>11</source>
          <target>11</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

However, as I mentioned before, this won’t work as you expect because the SonarJS plugin can’t be extended using Java.

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 :wink: