public static void setMetaClass(Object object, MetaClass metaClass) {
    GroovyObject groovyObject = ObjectUtil.asInstance(object, GroovyObject.class);
    if (groovyObject != null) {
      groovyObject.setMetaClass(metaClass);
      return;
    }
    ((MetaClassRegistryImpl) GroovySystem.getMetaClassRegistry()).setMetaClass(object, metaClass);
  }
Provides convenient access to Groovy language and runtime features.
By convention, all usages of Groovy's InvokerHelper and
ScriptBytecodeAdapter go through this class.

@author Peter Niederwieser
spock-core/src/main/java/org/spockframework/runtime/GroovyRuntimeUtil.java