Efficiently Assigning java-all Group to Java Projects in SonarQube

Hello everyone,

I am currently facing a requirement to add the java-all group to all projects that use the Java language in SonarQube. Given the large number of projects, manually doing this would be very time-consuming. Initially, there wasn’t a project template set up to handle this automatically, so I am looking for alternatives.

  • SonarQube Version: Community Edition v10.6

  • Deployment Method: [etc.]

    • I have explored the API documentation to find relevant queries for working with project languages, but I couldn’t find a direct solution.
    • One possible approach I considered is scripting a solution that fetches the entire list of projects, filters them by language, and then assigns the required group to these projects. However, I am interested in knowing if there are any existing methods or similar topics that address this requirement.
  • I would appreciate any suggestions for efficiently implementing this feature or references to similar cases discussed previously.

Thank you in advance for your assistance!

Best regards,
Ivan

Hey there.

This is probably your best bet. SonarQube does not provide a way to set permissions based on the languages used in the project.

This would probably look like:

  • GET api/projects/search - Get the list of projects
  • Iterate each project through GET api/measures/component setting metricKeys=ncloc_language_distribution
  • Parse that data before using POST api/permissions/add_group to adding permissions to that project to the java-all group.

:warning: Only the latest version of SonarQube Community Build is considered active, so you’ll need to upgrade and see if the situation is still replicable before we can help you.

Your upgrade path is:

10.6 → 24.12 → 25.3

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.