I may introduce a custom rule that checks our code whether it contains a deprecated using.
using foo.bar;
class FooClass {
Is there a possibility by custom rules or Sonar itself to check this code and fail the build due to usage of deprecated package foo.bar?
I'm going to work backward:
So I would recommend that you set add your new rule to your Quality Profile at Blocker severity (after all, you want it to block the build), set a quality gate error condition on New Blocker Issues and set up your Jenkins pipeline to respond appropriately.
If you're not using Jenkins, or not using Pipelines, there is also the Build Breaker plugin, altho its use is not recommended.