I ran into a use case where I needed this query and didn't see it posted already. Hopefully it helps! This can be used in the script console as a part of the script runner add-on.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.group.search.GroupPickerSearchService
import com.atlassian.crowd.embedded.api.Group
def groupSearch = ComponentAccessor.getComponent(GroupPickerSearchService)
def groupList = groupSearch.findGroups("")
def groupManager = ComponentAccessor.getGroupManager()
for (Group group in groupList){
log.error group.getName().toString()//print group names to log
log.error groupManager.getUsersInGroup(group)//print group members to log
}