fun setDelegationMode()

in src/main/kotlin/org/jetbrains/kotlin/tools/testutils/testUtils.kt [154:168]


fun setDelegationMode(path: String, project: Project, delegationMode: Boolean) {
    //TODO: set default mode? DefaultGradleProjectSettings.getInstance(project).isDelegatedBuild = false
    val projectSettings = GradleProjectSettings()
    projectSettings.externalProjectPath = path
    projectSettings.delegatedBuild = delegationMode
    projectSettings.distributionType = DistributionType.DEFAULT_WRAPPED // use default wrapper
    projectSettings.storeProjectFilesExternally = ThreeState.NO
    projectSettings.withQualifiedModuleNames()

    val systemSettings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID)
    @Suppress("UNCHECKED_CAST") val linkedSettings: Collection<ExternalProjectSettings> = systemSettings.getLinkedProjectsSettings() as Collection<ExternalProjectSettings>
    linkedSettings.filterIsInstance<GradleProjectSettings>().forEach { systemSettings.unlinkExternalProject(it.externalProjectPath) }

    systemSettings.linkProject(projectSettings)
}