NoClassDefFoundError org/sonarsource/analyzer/commons/xml/checks/SimpleXPathBasedCheck

Hello,
I’m writing custom rules in Java to check XML.
When connecting the JAR to Sonarqube the following error appears:

Bean initialization failed; nested exception is java.lang.NoClassDefFoundError: org/sonarsource/analyzer/commons/xml/checks/SimpleXPathBasedCheck

Can you help me?

Using the following dependencies in pom.xml:

<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api-impl</artifactId>
<version>10.2.1.78527</version>
<scope>test</scope>
</dependency >
<dependency>
<groupId>org.sonarsource.api.plugin</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>10.0.0.695</version>
<scope>provided</scope>
</ dependency>
<dependency>
<groupId>org.sonarsource.analyzer-commons</groupId>
<artifactId>sonar-xml-parsing</artifactId>
<version>2.7.0.1482</version>
<scope>provided</scope>
< exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.sonarsource.analyzer-commons </groupId>
<artifactId>sonar-analyzer-commons</artifactId>
<version>2.7.0.1482</version>
<scope>provided</scope>
</dependency>

rule example:

@Rule(key = "ClassRuleTestXml",
description = "Test rule xml."
+ "Report error in pom.",
priority = Priority.BLOCKER,
name = "ClassRuleTestXml",
tags = {"capgemini", "xml", "custom"})
public class ClassRuleTestXml extends SimpleXPathBasedCheck {

private static final Logger LOGGER = LoggerFactory.getLogger(ClassRuleTestXml.class);

@Sobrepor
public void scanFile(XmlFile file) {
LOGGER.error(file.getInputFile().filename());
Element e = file.getDocument().getDocumentElement();
reportIssue(e.getFirstChild(), "Test Error");
}
}

Can you help me?

I’m using:
Java 17.
Sonarqube 10.2

Thanks for helping.

Hi,

Per the docs there’s no support for writing rules about XML in Java. You’ll need to do that in XPath (1.0) or externally to SonarQube and import the results using the generic issue data format.

 
HTH,
Ann