private void runNoExit(String mainClassName, String[] args) throws Exception {
ClassPathRegistry classPathRegistry = new DefaultClassPathRegistry();
URL[] antClasspath = classPathRegistry.getClassPathUrls("ANT");
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});
}