Missing Class implementation in sonar-jave jar

Hi everyone,

When I try to modify rule definitions I find in the sonar github, specifically: sonar-java/DataStoredInSessionCheck.java at master · joansmith/sonar-java · GitHub

I’m getting a weird implementation mismatch, for example for the line:
import org.sonar.java.checks.methods.MethodMatcher;

The implementation of MethodMatcher is not available in the imported path, actually the methods folder only contains AbstractMethodDetection (and package-info). I’m using Intellij to develop the rules and build using maven with:

        <dependency>
            <groupId>org.sonarsource.java</groupId>
            <artifactId>sonar-java-plugin</artifactId>
            <version>7.18.0.31443</version>
        </dependency>

There are many other class definitions and folders also missing, e.g. NameCriteria, org.sonar.java.syntaxtoken, org.sonar.java.tag and many others

Any idea why aren’t those classes available for me?

There are additional sonar dependencies:

<dependencies>
    <dependency>
        <groupId>org.sonarsource.api.plugin</groupId>
        <artifactId>sonar-plugin-api</artifactId>
        <version>9.16.0.560</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.sonarsource.java</groupId>
        <artifactId>sonar-java-plugin</artifactId>
        <version>7.18.0.31443</version>
    </dependency>

    <!-- unit tests -->
    <dependency>
        <groupId>org.sonarsource.sonarqube</groupId>
        <artifactId>sonar-plugin-api-impl</artifactId>
        <version>10.0.0.68432</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.sonarsource.java</groupId>
        <artifactId>java-checks-testkit</artifactId>
        <version>7.19.0.31550</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.9.3</version>
        <scope>test</scope>
    </dependency>
</dependencies>

thx!

Hi,

I’m a little confused. Are you trying to develop custom rules inside a cloned/altered copy of the sonar-java/embedded analyzer project?

If so, that’s a road to frustration since you won’t be able to run your copy as-is; it will conflict with the embedded analyzer.

Beyond that, not all the APIs in the Java analyzer are exposed for use in other rules. You need to make sure what you’re trying to use is public.

 
HTH,
Ann