@NotNull public static List<Module> loadModuleScript( String moduleScriptFile, MessageCollector messageCollector) { Disposable disposable = new Disposable() { @Override public void dispose() {} }; CompilerConfiguration configuration = new CompilerConfiguration(); File defaultRuntimePath = CompilerPathUtil.getRuntimePath(); if (defaultRuntimePath != null) { configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, defaultRuntimePath); } configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, PathUtil.findRtJar()); File jdkAnnotationsPath = CompilerPathUtil.getJdkAnnotationsPath(); if (jdkAnnotationsPath != null) { configuration.add(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, jdkAnnotationsPath); } configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, moduleScriptFile); JetCoreEnvironment scriptEnvironment = JetCoreEnvironment.createCoreEnvironmentForJVM(disposable, configuration); GenerationState generationState = KotlinToJVMBytecodeCompiler.analyzeAndGenerate( new K2JVMCompileEnvironmentConfiguration( scriptEnvironment, messageCollector, false, BuiltinsScopeExtensionMode.ALL, false, BuiltinToJavaTypesMapping.ENABLED), false); if (generationState == null) { throw new CompileEnvironmentException( "Module script " + moduleScriptFile + " analyze failed"); } List<Module> modules = runDefineModules(moduleScriptFile, generationState.getFactory()); Disposer.dispose(disposable); if (modules == null) { throw new CompileEnvironmentException( "Module script " + moduleScriptFile + " compilation failed"); } if (modules.isEmpty()) { throw new CompileEnvironmentException("No modules where defined by " + moduleScriptFile); } return modules; }