public static GroovyObject parseGroovyScript(final Resource groovyScript,
                                                 final boolean failOnError) {
        try (val loader = newGroovyClassLoader()) {
            val groovyClass = loadGroovyClass(groovyScript, loader);
            if (groovyClass != null) {
                LOGGER.trace("Creating groovy object instance from class [{}]", groovyScript.getURI().getPath());
                return (GroovyObject) groovyClass.getDeclaredConstructor().newInstance();
            }
            LOGGER.warn("Groovy script at [{}] does not exist", groovyScript.getURI().getPath());
        } catch (final Exception e) {
            if (failOnError) {
                throw new RuntimeException(e);
            }
            LoggingUtils.error(LOGGER, e);
        }
        return null;
    }
Parse groovy script groovy object.

@param groovyScript the groovy script
@param failOnError  the fail on error
@return the groovy object
core/cas-server-core-scripting/src/main/java/org/apereo/cas/util/scripting/ScriptingUtils.java