services.add(FileLookup.class, fileLookup);
services.add(ModelRuleSourceDetector.class, modelRuleSourceDetector);
ScriptSource withImports = importsReader.withImports(scriptSource);
PluginDependenciesService pluginDependenciesService = new PluginDependenciesService(getSource());
services.add(PluginDependenciesService.class, pluginDependenciesService);
ScriptCompiler compiler = scriptCompilerFactory.createCompiler(withImports);
compiler.setClassloader(baseScope.getExportClassLoader());
boolean supportsPluginsBlock = ProjectScript.class.isAssignableFrom(scriptType);
String onPluginBlockError = supportsPluginsBlock ? null : "Only Project build scripts can contain plugins {} blocks";
PluginsAndBuildscriptTransformer scriptBlockTransformer = new PluginsAndBuildscriptTransformer(classpathClosureName, onPluginBlockError, documentationRegistry);
StatementExtractingScriptTransformer classpathScriptTransformer = new StatementExtractingScriptTransformer(classpathClosureName, scriptBlockTransformer);
compiler.setTransformer(classpathScriptTransformer);
ScriptRunner<? extends BasicScript> classPathScriptRunner = compiler.compile(scriptType);
classPathScriptRunner.getScript().init(target, services);
classPathScriptRunner.run();
List<PluginRequest> pluginRequests = pluginDependenciesService.getRequests();
PluginAware pluginAware = target instanceof PluginAware ? (PluginAware) target : null;
pluginRequestApplicator.applyPlugins(pluginRequests, scriptHandler, pluginAware, targetScope);
compiler.setClassloader(targetScope.getLocalClassLoader());