Unsatisfied dependency in SQ 7.6

sonarqube

(Svyatoslav) #1

Today I downloaded the SonarQube 7.6 and got an exception:

org.picocontainer.injectors.AbstractInjector$UnsatisfiableDependenciesException: com.analyzer.rules.IssuesLoaderSensor has unsatisfied dependency 'class org.sonar.api.profiles.RulesProfile' for constructor 'public com.analyzer.rules.IssuesLoaderSensor(org.sonar.api.config.Configuration,org.sonar.api.batch.fs.FileSystem,org.sonar.api.profiles.RulesProfile)' from ...

My constructor:

public IssuesLoaderSensor(final Configuration config, final FileSystem fileSystem, final RulesProfile rulesProfile) {
  this.config = config;
  this.fileSystem = fileSystem;
  this.profile = rulesProfile;
}

I don’t use deprecated api, what could be the problem?


(Scott) #2

Hi.

The RulesProfile is deprecated since SonarQube 5.2: https://github.com/SonarSource/sonarqube/commit/33851f1a19fcb539db658f22bd4015a01e6a9c9c. It was finally removed in SonarQube 7.6.


(Svyatoslav) #3

Hm, the file C:\Users\admin\.gradle\caches\modules-2\files-2.1\org.sonarsource.sonarqube\sonar-plugin-api\7.6\96797d65790726ebc4de618c52260226545b8ba0\sonar-plugin-api-7.6-sources.jar!\org\sonar\api\profiles\RulesProfile.java contains the old version of RulesProfile class.

Why can this be?


(Scott) #4

I’m not sure about what is your question… The class exists in the .jar, but your IssuesLoaderSensor class is instantiated by SonarQube Scanner and it’s responsible for creating instances of Configuration, FileSystem and RulesProfile classes (to call the class constructor).

In SonarQube 7.6, the SonarQube Scanner engine stopped providing instances of RulesProfile. Therefore, it won’t create instances of RulesProfile anymore.

You must change your code to use org.sonar.api.batch.rule.ActiveRules.


(Svyatoslav) #5

I understood about API.

In my project, the warnings about deprecated classes are enabled, but in this case it didn’t work:

tasks.withType(JavaCompile) {
  options.compilerArgs << "-Xlint:deprecation"
}

In the message above I’ve cited the path to the class file, which is in the Gradle cache. The class there doesn’t contain tags @deprecated, though API is of the 7.6. version. I don’t understand, why it is so.


(Scott) #6

Oh, now I see…

I said that it was deprecated in SonarQube 5.2, but it was not: “undo deprecation of RulesProfile”

It looks like they messed up. :slight_smile: I’m sorry for causing confusion.


(Julien Henry) #7

Hi all,

Short answer: RulesProfile was indeed removed from scanner side IoC container. Use ActiveRules instead. We were not able to mark it as deprecated, since it is still usable by server side extensions.

Long answer: This class is part of the oldest bits of SonarQube, and was shared between server and scanner extension points. We tried to deprecate it in 5.2 to notify plugin developers they should stop using it from scanner side extension points. But server side extension point developers were complaining that the deprecation was causing false positive issues on their code, so we decided to revert the deprecation.

You can easily replace it by ActiveRules, that is a specific scanner side component, and there since a long time so your plugin will be backward compatible with older SQ versions. I apologize for what is kind of zero-day API break, but due to the limited expressiveness of @Deprecated annotation, we had no better idea.