URL[] runtimeClasspath = classPathRegistry.getClassPathUrls("GRADLE_RUNTIME");
ClassLoader rootClassLoader = ClassLoader.getSystemClassLoader().getParent();
URLClassLoader antClassLoader = new URLClassLoader(antClasspath, rootClassLoader);
URLClassLoader runtimeClassLoader = new URLClassLoader(runtimeClasspath, antClassLoader);
Thread.currentThread().setContextClassLoader(runtimeClassLoader);
Class mainClass = runtimeClassLoader.loadClass(mainClassName);
Method mainMethod = mainClass.getMethod("main", String[].class);
mainMethod.invoke(null, new Object[]{args});
}
}