Bundling two different language scanner and sensors in one plugin

Can one Plugin setup two language profiles and rule definitions?

We are trying to bundle custom SQL sensor and associated quality rules in existing Java Custom Rules plugin which extends out of the box Java Plugin.

public class JavaCustomRulesPlugin implements Plugin {

    @Override
    public void define(Context context) {

        List<Object> list = new ArrayList<>();
        list.addAll(Arrays.asList(
                PropertyDefinition.builder(SQL.FILE_SUFFIXES_KEY).name("File Suffixes")
                        .description("Comma-separated list of suffixes of SQL files to analyze.").category(SQL.NAME)
                        .onQualifiers(Qualifiers.PROJECT).defaultValue(".sql,.pkg,.pks,.pkb").build(),
                SQL.class, SQLQualityProfile.class, SQLComplianceSensor.class,
                SQLComplianceCheckRegistrar.class));
        context.addExtensions(Collections.unmodifiableList(list));
        
        // Java custom rules
        context.addExtension(JavaCustomRulesDefinition.class);

        // Java custom rules registrar
        context.addExtension(JavaCustomRulesCheckRegistrar.class);

    }

I see lots of Rules being disable in log message and SonarQube server shuts down at the end.

[o.s.s.q.RegisterQualityGates] Sonar way legacy Gate: org.sonar.db.qualitygate.QualityGateDto@702984a2 
[o.s.s.r.r.RulesRegistrant] Register rules
[o.s.s.r.r.RulesRegistrant] Disable rule external_eslint_repo:vue/multiline-html-element-content-newline
[o.s.s.r.r.RulesRegistrant] Disable rule external_fbcontrib:S508C_NO_SETSIZE
[o.s.s.r.r.RulesRegistrant] Disable rule external_checkstyle:coding.NoFinalizerCheck
[o.s.s.r.r.RulesRegistrant] Disable rule docker:S4507
[o.s.s.r.r.RulesRegistrant] Disable rule typescript:S6303
...
...
...
[o.s.s.r.r.RulesRegistrant] Disable rule external_fbcontrib:NFF_NON_FUNCTIONAL_FIELD
[o.s.s.q.b.BuiltInQProfileRepositoryImpl] Load quality profiles
[g.u.s.s.p.SQLQualityProfile] SQLQualityProfile define() completed
[o.s.s.q.RegisterQualityProfiles] Register quality profiles
[o.s.s.q.RegisterQualityProfiles] Update profile kubernetes/Sonar way
[o.s.c.a.AnnotationConfigApplicationContext] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jdk.internal.loader.ClassLoaders$AppClassLoader@659e0bfd-org.sonar.server.qualityprofile.RegisterQualityProfiles': Initialization of bean failed; nested exception is BadRequestException{errors=[Rule was removed: kubernetes:S5849]}
[o.s.s.p.Platform] Background initialization failed. Stopping SonarQube

Can one plugin have two different language Scanners and Registrars?
Note: This was tested on both sonarqube-community-10.6.0.92116 and sonarqube-24.12.0.100206. Same errors in both versions.

Thank You.

Hey there.

If you’re looking for an example plugin that does this, I suggest sonar-iac

However, there’s no part of custom plugin development that should result in rules from other plugins being disabled.

Have you possibly removed some files from the lib/extensions directory of your SonarQube instance?

Thank you, Colin. I’ll take a look at your suggested Plugin code. Ours is a bit different since we are trying to merge Java plugin extension + Custom SQL plugin bundled into one.

Thanks.