DataNode<ModuleData> (@NotNull ProjectResolverContext resolverCtx, @NotNull IdeaModule gradleModule, @NotNull DataNode<ProjectData> projectDataNode) { GradleProject gradleProject = gradleModule.getGradleProject(); final String moduleName = resolverCtx.isUseQualifiedModuleNames() ? gradleProject.getName() : gradleModule.getName(); if (moduleName == null) { throw new IllegalStateException("Module with undefined name detected: " + gradleModule); } final ProjectData projectData = projectDataNode.getData(); final String mainModuleConfigPath = getModuleConfigPath(resolverCtx, gradleModule, projectData.getLinkedExternalProjectPath()); final String ideProjectPath = resolverCtx.getIdeProjectPath(); final String relativePath; boolean isUnderProjectRoot = FileUtil.isAncestor(projectData.getLinkedExternalProjectPath(), mainModuleConfigPath, false); if (isUnderProjectRoot) { relativePath = FileUtil.getRelativePath(projectData.getLinkedExternalProjectPath(), mainModuleConfigPath, '/'); } else { relativePath = String.valueOf(FileUtil.pathHashCode(mainModuleConfigPath)); } final String mainModuleFileDirectoryPath = ideProjectPath == null ? mainModuleConfigPath : ideProjectPath + '/' + (relativePath == null || relativePath.equals(".") ? "" : relativePath); if (ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) { LOG.info(String.format( "Creating module data ('%s') with the external config path: '%s'", gradleProject.getPath(), mainModuleConfigPath )); } String mainModuleId = getModuleId(resolverCtx, gradleModule); final ModuleData moduleData = new ModuleData(mainModuleId, GradleConstants.SYSTEM_ID, getDefaultModuleTypeId(), moduleName, mainModuleFileDirectoryPath, mainModuleConfigPath); ExternalProject externalProject = resolverCtx.getExtraProject(gradleModule, ExternalProject.class); if (externalProject != null) { GradleModuleDataKt.setGradlePath(moduleData, externalProject.getPath()); GradleModuleDataKt.setGradleIdentityPath(moduleData, getIdentityPath(resolverCtx, externalProject, projectData.getExternalName())); moduleData.setInternalName(getInternalModuleName(gradleModule, externalProject, resolverCtx)); moduleData.setGroup(externalProject.getGroup()); moduleData.setVersion(externalProject.getVersion()); moduleData.setDescription(externalProject.getDescription()); moduleData.setModuleName(moduleName); if (!resolverCtx.isResolveModulePerSourceSet()) { moduleData.setArtifacts(externalProject.getArtifacts()); moduleData.setPublication(new ProjectId(externalProject.getGroup(), externalProject.getName(), externalProject.getVersion())); } } File rootDir = gradleProject.getProjectIdentifier().getBuildIdentifier().getRootDir(); String rootProjectPath = ExternalSystemApiUtil.toCanonicalPath(rootDir.getPath()); boolean isComposite = !resolverCtx.getModels().getIncludedBuilds().isEmpty(); boolean isIncludedBuildTaskRunningSupported = isComposite && isIncludedBuildTaskRunningSupported(projectDataNode, resolverCtx); File mainBuildRootDir = resolverCtx.getModels().getMainBuild().getBuildIdentifier().getRootDir(); String mainBuildRootPath = ExternalSystemApiUtil.toCanonicalPath(mainBuildRootDir.getPath()); boolean isFromIncludedBuild = !rootProjectPath.equals(mainBuildRootPath); boolean useIncludedBuildPathPrefix = isFromIncludedBuild && isIncludedBuildTaskRunningSupported; String compositeBuildGradlePath = useIncludedBuildPathPrefix ? ":" + getRootProject(gradleProject).getName() : ""; GradleModuleDataKt.setIncludedBuild(moduleData, isFromIncludedBuild); String directoryToRunTask; if (compositeBuildGradlePath.isEmpty()) { directoryToRunTask = isUnderProjectRoot ? mainModuleConfigPath : rootProjectPath; } else { directoryToRunTask = mainBuildRootPath; } GradleModuleDataKt.setDirectoryToRunTask(moduleData, directoryToRunTask); return projectDataNode.createChild(ProjectKeys.MODULE, moduleData); }