Adjusting classpath for Maven sonar analysis

What are you trying to accomplish?

  • Support a new language? Yes
  • Extend an existing one? Which one? No
  • Add language-agnostic features? No
  • Something else? Yes

What’s your specific coding challenge in developing your plugin?
I’m developing a new plugin for JMeter/XML files and need the JMeter engine to be configured in order to access the XML files as POJO objects via JMeter’s own API and next perform analysis on the POJO representation.
I’m running Maven based scan and I’ve tried to provide access to the JMeter’s library folders with both -Dsonar.scanner.javaOpts="-Xbootclasspath/a: and -Dsonar.java.libraries= (although I doubt it can work as the plugin is not a Java one) but no success, I keep seeing java.lang.ClassNotFoundException. It’s strange as I’ve included in the Uber JAR most of the JMeter’s 3rd party dependencies but it doesn’t detect any.

Not sure how to move forward, looks like I’m stuck. Any options/suggestions?

Note: I’ve used the following software versions:

  • latest Sonar server Docker image 10.7
  • latest Sonar Maven plugin sonar-maven-plugin 5.0.0.4389
  • latest Sonar Maven plugin sonar-packaging-maven-plugin 1.23.0.740
  • latest Sonar Maven plugin sonar-analyzer-commons & sonar-xml-parsing 2.14.0.3087
  • the Sonar Plugin API version comes with Sonar analyzer commons dependency

Thank you

And, if relevant, please share the code that’s giving you problems:
Nothing specific yet.

Hi,

Welcome to the community!

It’s long-abandoned, but there is a JMeter plugin out there.

 
HTH,
Ann

Hi,

thanks for the quick answer; indeed, there is that project but it does something else and doesn’t rely on the JMeter framework at all, as I understood it simply evaluates the results of a JMeter run based on the JTL file it produces, it aggregates some KPIs and extracts information from this.
So the question remains: is there a possibility to adjust the classpath of the Maven analysis plugin run so it includes additional dependencies? Only the Java Plugin allows this via sonar.java.libraries parameter?

Thanks

Hi,

I don’t think you’re going to be able to adjust the plugin classpath to expand what’s already provided for you.

 
Ann

Thanks for the answer; so with Sonar plugin one is tied to the Uber JAR which enforces everything to be under a lib folder inside (unfortunately JMeter has it’s own expected folder structure with lib and lib/ext).
Sorry to insist, but just for the sake of clarity: with Java plugin one has this choice via sonar.java.libraries but other plugins don’t. Is my understanding correct?

Thank you

Hi,

Uhm… Are you asking if the Java analyzer has access to the project’s library information needed to fully analyze the code? Yes. And not all of the Java analyzer’s APIs are public.

 
HTH,
Ann

My communication skills show their limits :slight_smile:
In the documentation I can see:

sonar.java.libraries Comma-separated paths to files with third-party libraries (JAR or Zip files) used by your project. Wildcards can be used: sonar.java.libraries=path/to/Library.jar,directory/**/*.jar

As I understand a plugin that relies/extends on/a Java plugin can use this parameter to add to the classpath of the analyzer when running sonar-maven-plugin. This implies those libraries are outside of the Uber JAR created with the help of sonar-packaging-maven-plugin which adds dependencies inside the Uber JAR META-INF/lib folder.
This would allow me to add in the classpath my local JMeter install folder (its lib & lib/ext sub-folders where JAR files can be found) while running the analysis.

I also understand that Java Plugin is the only one allowing such thing; default plugin infrastructure doesn’t allow specifying extra paths other than what’s inside the Uber JAR.

Hi,

The sonar.java.libraries property tells analysis where to find the libraries of the project being analyzed in order for analysis to fully understand the classes referenced in the project. It is not a way to make additional resources available for use by your plugin.

 
HTH,
Ann