private <T> T instantiateAndConfigureExtension(Class<T> clazz) {
    try {
      Constructor<?>[] declaredConstructors = clazz.getDeclaredConstructors();
      Constructor<?> declaredConstructor = findBestFittingConstructor(declaredConstructors);
      if (declaredConstructor.getParameterCount() == 0) {
        Object extension = declaredConstructor.newInstance();
        configureExtension(extension);
        return clazz.cast(extension);
      } else {
        Object[] args = Arrays.stream(declaredConstructor.getParameters())
          .map(parameter -> getInjectionParameter(parameter, clazz))
          .toArray();

        return clazz.cast(declaredConstructor.newInstance(args));
      }
    } catch (Exception e) {
      throw new ExtensionException("Failed to instantiate extension '%s'", e).withArgs(clazz.getName());
    }

  }
Maintains a registry of global Spock extensions and their configuration objects,
which can be used to configure other extensions.

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