Pregunta

Cloned the examples found here https://github.com/SonarSource/sonar-examples and imported into IntelliJ

I'm having some problems with the example code

The imports fails in IntelliJ import org.sonar.plugins.java.api.JavaFileScanner; import org.sonar.plugins.java.api.JavaFileScannersFactory;

I seems that imports with package org.sonar.plugins.* is not found. Probably a dependency issue? In which jar are those classes bundled?

running mvn package seems to work, however IntelliJ does not find the classes

When upgrading sonar-plugin-api from version 4.1 to 4.2, the import org.sonar.api.resources.Java also breaks -> Running mvn package this time breaks the build with a compilation error

(I need 4.2 as that's the version we are running)

Has anybody managed to make the examples work?

And does anybody when the examples will be updated to 4.2?

¿Fue útil?

Solución

In order to make the example work in IntelliJ you have to workaround a buggy issue in this IDE:

In the pom.xml of the example you have this section :

<dependency>
  <groupId>org.codehaus.sonar-plugins.java</groupId>
  <artifactId>sonar-java-plugin</artifactId>
  <type>sonar-plugin</type>
  <version>1.5</version>
  <scope>provided</scope>
</dependency>

(Assuming you don't have maven auto import feature enabled) In order to make it work in IntelliJ you have to comment out the line <type>sonar-plugin</type> and click on the popup to import maven settings and then uncomment the line (but do not reimport settings). This will make the library available in IntelliJ classpath and thus compiling the project.

To answer your other question :

There is a breaking change between version 4.1 and 4.2. Thus the break you encounter. As of when this will be updated, I might give it a shot this week, but no real guarantee on that, as we need to keep some example up for LTS version (3.7).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top