Access Configuration From Custom JavaCheck

Then another option is to get the Configuration injected in your CheckRegistrar, and expose it as a static field that all your checks will be able to access. I don’t like exposing static fields, but here it is acceptable.

Regarding using the projectKey, you have to be careful of those points:

  • is your check supposed to work in SonarLint? I would suggest to disable it in SonarLint, since it is relying on an external DB, and that would slow down SonarLint
  • is your check supposed to work with branches and pull requests? You would have to get the data not only for the correct project/version, but also for the correct branch.