温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

15. Gradle编译其他应用代码流程(四) - Configure过程

发布时间:2020-07-14 11:15:05 来源:网络 阅读:1009 作者:rongwei84n 栏目:开发技术

接上一遍Load过程的博客来继续  14. Gradle编译其他应用代码流程(三) - Load过程


这一边继续讲Configure过程。


Configure过程源代码

文件路径:

subprojects\core\src\main\java\org\gradle\initialization\DefaultGradleLauncher.java

private void doBuildStages(Stage upTo) {
        ....

        if (stage == Stage.Load) {
            // Configure build
            buildOperationExecutor.run("Configure build", new Runnable() {
                @Override
                public void run() {
                    buildConfigurer.configure(gradle);

                    if (!gradle.getStartParameter().isConfigureOnDemand()) {
                        buildListener.projectsEvaluated(gradle);
                    }

                    modelConfigurationListener.onConfigure(gradle);
                }
            });

            stage = Stage.Configure;
        }
        ...
}


一. 首次看buildConfigurer.configure(gradle)


文件路径:

subprojects\core\src\main\java\org\gradle\configuration\DefaultBuildConfigurer.java

public void configure(GradleInternal gradle) {
        ...
        projectConfigurer.configureHierarchy(gradle.getRootProject());
        
    }


文件路径:

subprojects\core\src\main\java\org\gradle\execution\TaskPathProjectEvaluator.java

public class TaskPathProjectEvaluator implements ProjectConfigurer {
    ...
    public void configureHierarchy(ProjectInternal project) {
        project.evaluate();
        for (Project sub : project.getSubprojects()) {
            if (cancellationToken.isCancellationRequested()) {
                throw new BuildCancelledException();
            }
            ((ProjectInternal) sub).evaluate();
        }
    }
}


在configureHierarchy里面,首先执行根项目的evaluate(),然后循环执行它的子项目的evaluate()。

就像往下面看:

文件路径:

subprojects\core\src\main\java\org\gradle\api\internal\project\DefaultProject.java

public DefaultProject evaluate() {
        getProjectEvaluator().evaluate(this, state);
        state.rethrowFailure();
        return this;
    }



subprojects\core\src\main\java\org\gradle\configuration\project\LifecycleProjectEvaluator.java

public void evaluate(ProjectInternal project, ProjectStateInternal state) {
        ...

        state.setExecuting(true);
        try {
            delegate.evaluate(project, state);
        } catch (Exception e) {
            addConfigurationFailure(project, state, e);
        } finally {
            state.setExecuting(false);
            state.executed();
            notifyAfterEvaluate(listener, project, state);
        }
    }


subprojects\core\src\main\java\org\gradle\configuration\project\ConfigureActionsProjectEvaluator.java

public class ConfigureActionsProjectEvaluator implements ProjectEvaluator {
    ...

    public void evaluate(ProjectInternal project, ProjectStateInternal state) {
        for (ProjectConfigureAction configureAction : configureActions) {
            configureAction.execute(project);
        }
    }
}


subprojects\core\src\main\java\org\gradle\configuration\project\BuildScriptProcessor.java

public class BuildScriptProcessor implements ProjectConfigureAction {
    ...

    public void execute(ProjectInternal project) {
        ...
            ScriptPlugin configurer = configurerFactory.create(project.getBuildScriptSource(), project.getBuildscript(), project.getClassLoaderScope(), project.getBaseClassLoaderScope(), true);
            configurer.apply(project);
        ...
    }
}


接下来就会调用到ScriptPluginImpl.apply,这是我们上一遍讲过的。会去应用这个配置文件。具体怎么应用,需要看它生成的class文件。

文件路径在

D:\gradle_jar_cache\caches\3.1-snapshot-1\scripts-remapped\quality_cjfs2g3ij3bqjjsmf9bhahspf\2n69on6v0v04xd0c8c445muqy\dsld7eae713beda1bd9e69f8461da734880\classes


截个class内容的图:


15. Gradle编译其他应用代码流程(四) - Configure过程

 

这是因为我们的gradle文件配置了3个plugin

apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'findbugs'


所以,在configure阶段,它会去解析我们的配置文件,并且去加载我们配置的plugin插件。

以加载pmd插件为例,贴一个调用堆栈:

java.lang.Exception: Sandy findPluginDescriptor pluginId: org.gradle.pmd
	at org.gradle.api.internal.plugins.ClassloaderBackedPluginDescriptorLocator.findPluginDescriptor(ClassloaderBackedPluginDescriptorLocator.java:31)
	at org.gradle.api.internal.plugins.DefaultPluginRegistry$1.load(DefaultPluginRegistry.java:59)
	at org.gradle.api.internal.plugins.DefaultPluginRegistry$1.load(DefaultPluginRegistry.java:51)
	at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
	at com.google.common.cache.LocalCache.get(LocalCache.java:3934)
	at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938)
	at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821)
	at org.gradle.api.internal.plugins.DefaultPluginRegistry.uncheckedGet(DefaultPluginRegistry.java:149)
	at org.gradle.api.internal.plugins.DefaultPluginRegistry.lookup(DefaultPluginRegistry.java:138)
	at org.gradle.api.internal.plugins.DefaultPluginRegistry.lookup(DefaultPluginRegistry.java:127)
	at org.gradle.api.internal.plugins.DefaultPluginRegistry.lookup(DefaultPluginRegistry.java:121)
	at org.gradle.api.internal.plugins.DefaultPluginRegistry.lookup(DefaultPluginRegistry.java:121)
	at org.gradle.api.internal.plugins.DefaultPluginRegistry.lookup(DefaultPluginRegistry.java:121)
	at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:108)
	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyType(DefaultObjectConfigurationAction.java:113)
	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:36)
	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:80)
	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:136)
	at org.gradle.groovy.scripts.DefaultScript.apply(DefaultScript.java:114)
	at org.gradle.api.Script$apply$0.callCurrent(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
	at quality_cjfs2g3ij3bqjjsmf9bhahspf.run(E:\work_space\Android-Prototype\config\quality.gradle:2)
	
	at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:176)
	at org.gradle.configuration.DefaultScriptTarget.addConfiguration(DefaultScriptTarget.java:74)
	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:181)
	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyScript(DefaultObjectConfigurationAction.java:102)
	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$000(DefaultObjectConfigurationAction.java:36)
	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$1.run(DefaultObjectConfigurationAction.java:62)
	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:136)
	at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:44)
	at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.java:34)
	at org.gradle.api.Script$apply$0.callCurrent(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
	at build_840r8chxz90tc75jy1mlavsji.run(E:\work_space\Android-Prototype\app\build.gradle:3)
	at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:176)
	at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:77)
	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:181)
	at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:38)
	at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:25)
	at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
	at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
	at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:573)
	at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:125)
	at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:47)
	at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
	at org.gradle.initialization.DefaultGradleLauncher$2.run(DefaultGradleLauncher.java:151)
	at org.gradle.internal.Factories$1.create(Factories.java:22)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:53)
	at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:148)
	at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:33)
	at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:112)
	at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:106)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:63)
	at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
	at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:92)
	at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:67)
	at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:31)
	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:43)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:42)
	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:79)
	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:51)
	at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:54)
	at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:173)
	at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:250)
	at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:217)
	at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:33)
	at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:210)
	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:174)
	at org.gradle.launcher.Main.doAction(Main.java:33)
	at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
	at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
	at org.gradle.launcher.GradleMain.main(GradleMain.java:24)


最后是在ClassloaderBackedPluginDescriptorLocator.findPluginDescriptor方法里面load plugin。


文件路径:

subprojects\core\src\main\java\org\gradle\api\internal\plugins\ClassloaderBackedPluginDescriptorLocator.java

public class ClassloaderBackedPluginDescriptorLocator implements PluginDescriptorLocator {

    ...

    public PluginDescriptor findPluginDescriptor(String pluginId) {
        URL resource = classLoader.getResource("META-INF/gradle-plugins/" + pluginId + ".properties");
        Exception ex = new Exception("Sandy findPluginDescriptor pluginId: " + pluginId);
        ex.printStackTrace();
        if (resource == null) {
            return null;
        } else {
            return new PluginDescriptor(resource);
        }
    }

}


它会去找META-INF/gradle-plugins/'pluginid'.properties这个文件。

以pmd为例, pmd的这个配置文件路径是

subprojects\code-quality\src\main\resources\META-INF\gradle-plugins\org.gradle.pmd.properties


15. Gradle编译其他应用代码流程(四) - Configure过程


内容是 implementation-class=org.gradle.api.plugins.quality.PmdPlugin  它表示pmd插件的描述类是PmdPlugin.java,需要去加载这个类。



二. 加载task

在Configure阶段会load所需要的task,以pmd为例,下面是调用堆栈:

10:10:14.934 [ERROR] [system.err] java.lang.Exception: Sandy pmd init
10:10:14.934 [ERROR] [system.err] 	at org.gradle.api.plugins.quality.Pmd.<init>(Pmd.java:68)
10:10:14.934 [ERROR] [system.err] 	at org.gradle.api.plugins.quality.Pmd_Decorated.<init>(Unknown Source)
10:10:14.934 [ERROR] [system.err] 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
10:10:14.934 [ERROR] [system.err] 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
10:10:14.934 [ERROR] [system.err] 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
10:10:14.934 [ERROR] [system.err] 	at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
10:10:14.934 [ERROR] [system.err] 	at org.gradle.api.internal.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:56)
10:10:14.934 [ERROR] [system.err] 	at org.gradle.api.internal.ClassGeneratorBackedInstantiator.newInstance(ClassGeneratorBackedInstantiator.java:36)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:121)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.api.internal.project.taskfactory.TaskFactory$1.call(TaskFactory.java:118)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.util.GUtil.uncheckedCall(GUtil.java:401)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.api.internal.AbstractTask.injectIntoNewInstance(AbstractTask.java:176)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.api.internal.project.taskfactory.TaskFactory.create(TaskFactory.java:118)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.api.internal.project.taskfactory.TaskFactory.createTask(TaskFactory.java:77)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.createTask(AnnotationProcessingTaskFactory.java:46)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.api.internal.project.taskfactory.DependencyAutoWireTaskFactory.createTask(DependencyAutoWireTaskFactory.java:39)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.api.internal.tasks.DefaultTaskContainer.create(DefaultTaskContainer.java:63)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.api.internal.project.DefaultProject.task(DefaultProject.java:976)
10:10:14.935 [ERROR] [system.err] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:10:14.935 [ERROR] [system.err] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
10:10:14.935 [ERROR] [system.err] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
10:10:14.935 [ERROR] [system.err] 	at java.lang.reflect.Method.invoke(Method.java:483)
10:10:14.935 [ERROR] [system.err] 	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
10:10:14.935 [ERROR] [system.err] 	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:382)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.internal.metaobject.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:170)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.internal.metaobject.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:96)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.internal.metaobject.MixInClosurePropertiesAsMethodsDynamicObject.invokeMethod(MixInClosurePropertiesAsMethodsDynamicObject.java:30)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.internal.metaobject.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:163)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:83)
10:10:14.935 [ERROR] [system.err] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:10:14.935 [ERROR] [system.err] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
10:10:14.935 [ERROR] [system.err] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
10:10:14.935 [ERROR] [system.err] 	at java.lang.reflect.Method.invoke(Method.java:483)
10:10:14.935 [ERROR] [system.err] 	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
10:10:14.935 [ERROR] [system.err] 	at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:941)
10:10:14.935 [ERROR] [system.err] 	at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1264)
10:10:14.935 [ERROR] [system.err] 	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1217)
10:10:14.935 [ERROR] [system.err] 	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
10:10:14.935 [ERROR] [system.err] 	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
10:10:14.935 [ERROR] [system.err] 	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
10:10:14.935 [ERROR] [system.err] 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
10:10:14.935 [ERROR] [system.err] 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:182)
10:10:14.935 [ERROR] [system.err] 	at quality_cjfs2g3ij3bqjjsmf9bhahspf.run(E:\work_space\Android-Prototype\config\quality.gradle:49)
10:10:14.935 [ERROR] [system.err] 	at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:176)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.configuration.DefaultScriptTarget.addConfiguration(DefaultScriptTarget.java:74)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:181)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyScript(DefaultObjectConfigurationAction.java:102)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$000(DefaultObjectConfigurationAction.java:36)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$1.run(DefaultObjectConfigurationAction.java:62)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:136)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:44)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.java:34)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.api.Script$apply$0.callCurrent(Unknown Source)
10:10:14.936 [ERROR] [system.err] 	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
10:10:14.936 [ERROR] [system.err] 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
10:10:14.936 [ERROR] [system.err] 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
10:10:14.936 [ERROR] [system.err] 	at build_840r8chxz90tc75jy1mlavsji.run(E:\work_space\Android-Prototype\app\build.gradle:3)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:176)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.configuration.ProjectScriptTarget.addConfiguration(ProjectScriptTarget.java:77)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:181)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:38)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:25)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:573)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.api.internal.project.DefaultProject.evaluate(DefaultProject.java:125)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:47)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:38)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.initialization.DefaultGradleLauncher$2.run(DefaultGradleLauncher.java:151)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.internal.Factories$1.create(Factories.java:22)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:53)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:148)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:33)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:112)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:106)
10:10:14.936 [ERROR] [system.err] 	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:63)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:92)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:67)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:31)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:43)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:42)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:79)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:51)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:54)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:173)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:250)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:217)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:33)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:210)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:174)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.Main.doAction(Main.java:33)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
10:10:14.937 [ERROR] [system.err] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
10:10:14.937 [ERROR] [system.err] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
10:10:14.937 [ERROR] [system.err] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
10:10:14.937 [ERROR] [system.err] 	at java.lang.reflect.Method.invoke(Method.java:483)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
10:10:14.937 [ERROR] [system.err] 	at org.gradle.launcher.GradleMain.main(GradleMain.java:24)




三. buildListener.projectsEvaluated发送通知

文件路径:

subprojects\core\src\main\java\org\gradle\initialization\DefaultGradleLauncher.java

if (!gradle.getStartParameter().isConfigureOnDemand()) {
      buildListener.projectsEvaluated(gradle);
}

发送projectsEvaluated通知



四. 至此Configure阶段完成

这个阶段主要load了配置文件中的各种plugin;另外它的调用方法是通过加载生成的class文件来进行的。

D:\gradle_jar_cache\caches\3.1-snapshot-1\scripts-remapped\quality_cjfs2g3ij3bqjjsmf9bhahspf\2n69on6v0v04xd0c8c445muqy\dsld7eae713beda1bd9e69f8461da734880\classes

这样不同的配置文件可以用不同的类来执行加载动作,而代码保持一致。


接下来编译进入build阶段。

// After this point, the GradleLauncher cannot be reused
stage = Stage.Build;


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI