首页 > 代码库 > Gradle源码入门五

Gradle源码入门五

分析DefaultGradleLauncher.java

private void doBuildStages(Stage upTo) 函数的第二步

        // Evaluate settings script
        SettingsInternal settings = settingsHandler.findAndLoadSettings(gradle);
        buildListener.settingsEvaluated(settings);

从 startParameter 开始
StartParameter{taskRequests=[DefaultTaskExecutionRequest{args=[hello],projectPath='null'}], excludedTaskNames=[], currentDir=C:\Users\xxx\workspace\Gradle, searchUpwards=true, projectProperties={}, systemPropertiesArgs={}, gradleUserHomeDir=C:\Users\xxx\.gradle, gradleHome=C:\gradle-2.2.1, logLevel=LIFECYCLE, showStacktrace=INTERNAL_EXCEPTIONS, buildFile=null, initScripts=[], dryRun=false, rerunTasks=false, recompileScripts=false, offline=false, refreshDependencies=false, parallelThreadCount=0, configureOnDemand=false}

这个变量有一个searchUpwards, 如果为true,找
currentDir + settings.gradle
then loop:
	parentDir + settings.gradle
	parentDir/master + settings.gradle

找到一个有效的即止
------------------
如果为false,找到父目录即止
=========================
在org.gradle.initialization SettingsLocation.java

    public SettingsLocation(File settingsDir, File settingsFile) {
        this.settingsDir = settingsDir;
        this.settingsScriptSource = settingsFile == null
                ? new StringScriptSource("empty settings script", "")
                : new UriScriptSource("settings file", settingsFile);
    }

如果没有任何settings文件, settingdir就是currentDir, settingsFile is null

过程基本和init 文件相似,调用DefaultScriptPluginFactory.java 里面的 ScriptPluginImpl.apply 

结果

技术分享

Gradle源码入门五