diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinSourceSetConvention.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinSourceSetConvention.kt index e3b8a65ccd1..04b2b58c21a 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinSourceSetConvention.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/dsl/KotlinSourceSetConvention.kt @@ -39,12 +39,17 @@ import kotlin.reflect.KProperty @ExperimentalKotlinGradlePluginApi object KotlinSourceSetConvention : ReadOnlyProperty, NamedDomainObjectProvider> { + + internal class Trace : Throwable() + override fun getValue( thisRef: NamedDomainObjectContainer, property: KProperty<*>, ): NamedDomainObjectProvider { val name = property.name - return if (name in thisRef.names) thisRef.named(name) else thisRef.register(name) { sourceSet -> - sourceSet.isRegisteredByKotlinSourceSetConventionAt = Throwable() + if (name in thisRef.names) return thisRef.named(name) + val trace = Trace() + return thisRef.register(name) { sourceSet -> + sourceSet.isRegisteredByKotlinSourceSetConventionAt = trace } } @@ -53,7 +58,7 @@ object KotlinSourceSetConvention : * This will be null if SourceSet already existed and was referenced using the convention, or of no convention was used at all. */ @Suppress("UnusedReceiverParameter") // Diagnostic is wrong - internal var KotlinSourceSet.isRegisteredByKotlinSourceSetConventionAt: Throwable? + internal var KotlinSourceSet.isRegisteredByKotlinSourceSetConventionAt: Trace? by extrasReadWriteProperty("isRegisteredByKotlinSourceSetConvention") private set }