[groovy] How to get a list of all users in a group?

Is there a way in groovy to get a list of all users in a group?

I found this snippet (https://snippets.xwiki.org/xwiki/bin/view/Extension/Retrieve%20users%20from%20a%20specific%20group) that seems to accomplish that by checking for all users whether the user is a member of the group. This appears to be rather inefficient and slow for many groups to check that only contain a few members…

I found this snippet (https://snippets.xwiki.org/xwiki/bin/view/Extension/Retrieve%20users%20from%20a%20specific%20group)

This API is oldish.

See https://extensions.xwiki.org/xwiki/bin/view/Extension/User%20Module/Scripting/#HGroup27smembers for examples using the new group API. The examples are in Velocity, but the groovy version is not very different and should look something like

services.user.group.getMembers(new DocumentReference('xwiki', 'XWiki', 'MyGroup')

Thanks for the information and pointer, i managed to make it work with this: