How to configure LDAP in Nexus3 using groovy script

Please see this answer from a sonatype staff member in a similar question.

In short: don’t use groovy for this, use the REST API.