mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Kotlin, Gradle] Load generated sources in KMP projects only if KGP version >= 2.3.0
Unify solution both for KMP and JVM projects ^KTIJ-37636 Verification Pending (cherry picked from commit ee365595951e41187671b808c9e248a778dcd1d2) IJ-MR-192445 GitOrigin-RevId: 15ff021b41668487a96236ad4f361a10a82cc6dd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
938b4cf35c
commit
d80ed8cda1
+3
-1
@@ -120,7 +120,9 @@ class KotlinMPPGradleModelBuilder : AbstractModelBuilderService() {
|
||||
): List<KotlinSourceSetImpl> {
|
||||
val sourceSetBuilder = KotlinSourceSetBuilder(importingContext)
|
||||
return importingContext.kotlinExtensionReflection.sourceSets
|
||||
.mapNotNull { sourceSetReflection -> sourceSetBuilder.buildKotlinSourceSet(sourceSetReflection) }
|
||||
.mapNotNull { sourceSetReflection ->
|
||||
sourceSetBuilder.buildKotlinSourceSet(sourceSetReflection, importingContext.kotlinGradlePluginVersion)
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildTargets(
|
||||
|
||||
+9
-2
@@ -4,9 +4,11 @@ package org.jetbrains.kotlin.idea.gradleTooling.builders
|
||||
import org.gradle.api.Named
|
||||
import org.jetbrains.kotlin.idea.gradleTooling.IdeaKotlinExtras
|
||||
import org.jetbrains.kotlin.idea.gradleTooling.KotlinDependency
|
||||
import org.jetbrains.kotlin.idea.gradleTooling.KotlinGradlePluginVersion
|
||||
import org.jetbrains.kotlin.idea.gradleTooling.KotlinSourceSetImpl
|
||||
import org.jetbrains.kotlin.idea.gradleTooling.MultiplatformModelImportingContext
|
||||
import org.jetbrains.kotlin.idea.gradleTooling.builders.KotlinAndroidSourceSetInfoBuilder.buildKotlinAndroidSourceSetInfo
|
||||
import org.jetbrains.kotlin.idea.gradleTooling.getKotlinSourceSetGeneratedSourceRoots
|
||||
import org.jetbrains.kotlin.idea.gradleTooling.isHMPPEnabled
|
||||
import org.jetbrains.kotlin.idea.gradleTooling.reflect.KotlinSourceSetReflection
|
||||
import org.jetbrains.kotlin.idea.gradleTooling.supportsKotlinAndroidSourceSetInfo
|
||||
@@ -38,14 +40,19 @@ internal class KotlinSourceSetBuilder(
|
||||
.keys
|
||||
}
|
||||
|
||||
fun buildKotlinSourceSet(sourceSetReflection: KotlinSourceSetReflection): KotlinSourceSetImpl? {
|
||||
fun buildKotlinSourceSet(
|
||||
sourceSetReflection: KotlinSourceSetReflection,
|
||||
kotlinGradlePluginVersion: KotlinGradlePluginVersion?,
|
||||
): KotlinSourceSetImpl? {
|
||||
val languageSettings = sourceSetReflection.languageSettings
|
||||
?.let { KotlinLanguageSettingsBuilder.buildComponent(it) }
|
||||
?: return null
|
||||
|
||||
val sourceDirs = sourceSetReflection.kotlin?.srcDirs ?: emptySet()
|
||||
val resourceDirs = sourceSetReflection.resources?.srcDirs ?: emptySet()
|
||||
val generatedKotlinDirs = sourceSetReflection.generatedSources?.srcDirs?.toSet() ?: emptySet()
|
||||
val generatedKotlinDirs = sourceSetReflection
|
||||
.getKotlinSourceSetGeneratedSourceRoots(kotlinGradlePluginVersion)
|
||||
.map { it.toFile() }.toSet()
|
||||
val dependsOnSourceSets = sourceSetReflection.dependsOn.map { it.name }.toSet()
|
||||
val additionalVisibleSourceSets = sourceSetReflection.additionalVisibleSourceSets.map { it.name }.toSet()
|
||||
|
||||
|
||||
+12
-8
@@ -13,21 +13,25 @@ private const val MIN_KOTLIN_PLUGIN_VERSION = "2.3.0"
|
||||
internal fun Project.getKotlinSourceSetGeneratedSourceRoots(
|
||||
kotlinPluginVersion: KotlinGradlePluginVersion?
|
||||
): List<Path> {
|
||||
if (kotlinPluginVersion == null || kotlinPluginVersion < MIN_KOTLIN_PLUGIN_VERSION) return emptyList()
|
||||
|
||||
val kotlinExtension = project.extensions.findByName("kotlin") ?: return emptyList()
|
||||
val kotlinExtensionClass = kotlinExtension.javaClass
|
||||
val getSourceSets = kotlinExtensionClass.getMethodOrNull("getSourceSets") ?: return emptyList()
|
||||
val sourceSets = getSourceSets.invoke(kotlinExtension) as NamedDomainObjectCollection<*>
|
||||
val generatedSourceRoots = sourceSets.map { it as Named }.flatMap {
|
||||
it.getKotlinSourceSetGeneratedSourceRoots() ?: emptyList()
|
||||
val generatedSourceRoots = sourceSets.map { KotlinSourceSetReflection(it as Named) }.flatMap {
|
||||
it.getKotlinSourceSetGeneratedSourceRoots(kotlinPluginVersion)
|
||||
}
|
||||
return generatedSourceRoots.toList()
|
||||
}
|
||||
|
||||
private fun Named.getKotlinSourceSetGeneratedSourceRoots(): List<Path>? {
|
||||
return KotlinSourceSetReflection(this).generatedSources?.srcDirs?.map {
|
||||
@Suppress("IO_FILE_USAGE") // Gradle API
|
||||
it.toPath()
|
||||
internal fun KotlinSourceSetReflection.getKotlinSourceSetGeneratedSourceRoots(
|
||||
kotlinPluginVersion: KotlinGradlePluginVersion?
|
||||
): List<Path> {
|
||||
return if (kotlinPluginVersion == null || kotlinPluginVersion < MIN_KOTLIN_PLUGIN_VERSION) {
|
||||
emptyList()
|
||||
} else {
|
||||
generatedSources?.srcDirs?.map {
|
||||
@Suppress("IO_FILE_USAGE") // Gradle API
|
||||
it.toPath()
|
||||
} ?: emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user