Gradel源码入门二

在org.gradle.launcher.bootstrap  ProcessBootstrap.java中

private void runNoExit(String mainClassName, String[] args) throws Exception {//new DefaultModuleRegistry, 做了大量初始化的工作,查找classpath结构
        ClassPathRegistry classPathRegistry = new DefaultClassPathRegistry(new DefaultClassPathProvider(new DefaultModuleRegistry()));
        ClassLoaderFactory classLoaderFactory = new DefaultClassLoaderFactory();//找到Ant相关的jar包, 分析jar包里面的 META-INF/MANIFEST.MF 属性
        ClassPath antClasspath = classPathRegistry.getClassPath("ANT");//找gradle相关的包,分析gradle-launcher-2.x.jar 包里面的gradle-launcher-classpath.properties
        ClassPath runtimeClasspath = classPathRegistry.getClassPath("GRADLE_RUNTIME");
        ClassLoader antClassLoader = classLoaderFactory.createIsolatedClassLoader(antClasspath);
        ClassLoader runtimeClassLoader = new MutableURLClassLoader(antClassLoader, runtimeClasspath);
        Thread.currentThread().setContextClassLoader(runtimeClassLoader);
        Class<?> mainClass = runtimeClassLoader.loadClass(mainClassName);
        Object entryPoint = mainClass.newInstance();
        Method mainMethod = mainClass.getMethod("run", String[].class);
        mainMethod.invoke(entryPoint, new Object[]{args});
    }

mainMethod   
org. gradle. launcher. bootstrap.EntryPoint 的run函数
这是由于
public class Main extends EntryPoint

你可能感兴趣的:(gradle)