eraonel
(Mikael Petterson)
November 2, 2023, 11:52am
1
SQ version: 9.9.2.77730
Zipped sonar
we are running a custom rules plugin.
We have a rule that uses ClassPatternsUtils class
and we have the following dependency in our maven project for the custom rules plugin.
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-java-plugin</artifactId>
<version>7.24.0.32100</version>
<type>sonar-plugin</type>
<scope>provided</scope>
I check that git repo:
https://github.com/SonarSource/sonar-java/blob/7.24.0.32100/java-checks/src/main/java/org/sonar/java/checks/helpers/ClassPatternsUtils.java
we are trying to run:
mvn sonar:sonar
Then we get the following output:
[2023-11-01T13:12:01.141Z] [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project mje: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar failed: A required class was missing while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar: org/sonar/java/checks/helpers/ClassPatternsUtils
Do we need to update anything on the SQ server?
br,
//mike
eraonel
(Mikael Petterson)
November 3, 2023, 2:29pm
2
Two questions:
Should the sonar-java library be bundled with my custom rules plugin?
If that is the case I could not see it in the jar file:
0 11-03-2023 08:22 META-INF/lib/
4190123 11-03-2023 08:22 META-INF/lib/org.eclipse.jdt.core-3.33.0.jar
104269 11-03-2023 08:22 META-INF/lib/org.eclipse.core.contenttype-3.8.200.jar
19936 11-03-2023 08:22 META-INF/lib/jsr305-3.0.2.jar
196772 11-03-2023 08:22 META-INF/lib/sonar-regex-parsing-2.7.0.1482.jar
1539745 11-03-2023 08:22 META-INF/lib/org.eclipse.osgi-3.18.300.jar
3160927 11-03-2023 08:22 META-INF/lib/ecj-3.33.0.jar
2199 11-03-2023 08:22 META-INF/lib/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
610199 11-03-2023 08:22 META-INF/lib/java-frontend-7.24.0.32100.jar
150535 11-03-2023 08:22 META-INF/lib/org.eclipse.equinox.common-3.17.0.jar
41125 11-03-2023 08:22 META-INF/lib/slf4j-api-1.7.36.jar
119174 11-03-2023 08:22 META-INF/lib/org.eclipse.core.commands-3.10.300.jar
20165 11-03-2023 08:22 META-INF/lib/org.osgi.service.prefs-1.1.2.jar
10255470 11-03-2023 08:22 META-INF/lib/jdt-7.24.0.32100-shaded.jar
587402 11-03-2023 08:22 META-INF/lib/commons-lang3-3.12.0.jar
138992 11-03-2023 08:22 META-INF/lib/org.eclipse.equinox.preferences-3.10.100.jar
304321 11-03-2023 08:22 META-INF/lib/org.eclipse.text-3.12.300.jar
8781 11-03-2023 08:22 META-INF/lib/j2objc-annotations-1.3.jar
76224 11-03-2023 08:22 META-INF/lib/org.eclipse.core.runtime-3.26.100.jar
258075 11-03-2023 08:22 META-INF/lib/gson-2.8.9.jar
323669 11-03-2023 08:22 META-INF/lib/picocontainer-2.14.1.jar
116937 11-03-2023 08:22 META-INF/lib/org.eclipse.core.jobs-3.13.200.jar
4617 11-03-2023 08:22 META-INF/lib/failureaccess-1.0.1.jar
35519 11-03-2023 08:22 META-INF/lib/sonar-performance-measure-2.7.0.1482.jar
167914 11-03-2023 08:22 META-INF/lib/sslr-squid-bridge-2.6.1.jar
208835 11-03-2023 08:22 META-INF/lib/checker-qual-3.12.0.jar
197897 11-03-2023 08:22 META-INF/lib/sslr-core-1.24.0.633.jar
24722 11-03-2023 08:22 META-INF/lib/troubleshooter-1.1.10.jar
36875 11-03-2023 08:22 META-INF/lib/osgi.annotation-8.0.1.jar
15979 11-03-2023 08:22 META-INF/lib/error_prone_annotations-2.11.0.jar
914262 11-03-2023 08:22 META-INF/lib/org.eclipse.core.resources-3.18.200.jar
112840 11-03-2023 08:22 META-INF/lib/sonar-analyzer-commons-2.7.0.1482.jar
2959479 11-03-2023 08:22 META-INF/lib/guava-31.1-jre.jar
If it is not the case that sonar-java is bundled where should the dependency come from?
br.
//mike
ganncamp
(G Ann Campbell)
November 6, 2023, 6:36pm
3
Hi mike,
Are you sure those helpers
classes are actually public
? My off-hand guess at the problem is that they’re not.
Ann
eraonel
(Mikael Petterson)
November 7, 2023, 7:54am
4
@ganncamp this from the sonar-java github.
and I don’t get any compile errors in my custom rules plugin.
What versions of sonar-java and sonar dependencies should I use in our custom rules plugin in the pom.xml
<dependency>
<groupId>org.sonarsource.api.plugin</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>9.14.0.375</version>
<!-- mandatory scope -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-java-plugin</artifactId>
<version>7.24.0.32100</version>
<type>sonar-plugin</type>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.osgi.service</groupId>
<artifactId>org.osgi.service.prefs</artifactId>
</exclusion>
</exclusions>
</dependency>
Is it correct?
ganncamp
(G Ann Campbell)
November 7, 2023, 12:41pm
6
Hi,
Mikael Petterson:
Is it correct?
I’m not qualified to judge. I’ve flagged this for more expert eyes.
Ann
Hi Mikael, the class you are trying to use in your code is not part of the org.sonar.plugins.java.api
package (the public Sonar APIs), and you will not be able to use it at runtime inside SQ. Within your IDE you do not see issues and you can also compile your code because of the maven dependency, but the classes will not be accessible at runtime inside the SQ instance.
eraonel
(Mikael Petterson)
November 10, 2023, 7:22am
9
@Leonardo_Pilastri so we can only depend on classes in package org.sonar.plugins.java.api
even if they are public.
But we are supposed to have this java dependency in our pom.xml since we use the,
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor class.
Since we need to add the dependency to our custom plugin is there a way to only include this package at compile time when we build with maven?
br,
//mikael
To my knowledge, Maven does not provide the possibility to import only a package from a dependency. I think you could configure this through your IDE though.