[Gradle] Add deprecated accessor to sourceSets inside KotlinSourceSet
Apparently, using such an approach is a popular case especially for configuring 'dependsOn' parameter. And we should simplify user migration to more restricted DSL. ^KT-64722 Verification Pending
This commit is contained in:
committed by
Space Team
parent
eb663117c7
commit
5fba2962b9
@@ -1109,6 +1109,7 @@ public abstract interface class org/jetbrains/kotlin/gradle/plugin/KotlinSourceS
|
||||
public abstract fun getLanguageSettings ()Lorg/jetbrains/kotlin/gradle/plugin/LanguageSettingsBuilder;
|
||||
public abstract fun getResources ()Lorg/gradle/api/file/SourceDirectorySet;
|
||||
public abstract fun getRuntimeOnlyMetadataConfigurationName ()Ljava/lang/String;
|
||||
public abstract fun getSourceSets ()Lorg/gradle/api/NamedDomainObjectContainer;
|
||||
public abstract fun kotlin (Lkotlin/jvm/functions/Function1;)Lorg/gradle/api/file/SourceDirectorySet;
|
||||
public abstract fun kotlin (Lorg/gradle/api/Action;)Lorg/gradle/api/file/SourceDirectorySet;
|
||||
public abstract fun languageSettings (Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlin/gradle/plugin/LanguageSettingsBuilder;
|
||||
|
||||
+9
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.plugin
|
||||
|
||||
import org.gradle.api.Action
|
||||
import org.gradle.api.Named
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.file.SourceDirectorySet
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinGradlePluginDsl
|
||||
import org.jetbrains.kotlin.tooling.core.HasMutableExtras
|
||||
@@ -47,4 +48,12 @@ interface KotlinSourceSet : Named, HasProject, HasMutableExtras, HasKotlinDepend
|
||||
|
||||
val customSourceFilesExtensions: Iterable<String> // lazy iterable expected
|
||||
fun addCustomSourceFilesExtensions(extensions: List<String>) {}
|
||||
|
||||
@Deprecated(
|
||||
"Accessing 'sourceSets' container inside another KotlinSourceSet is deprecated. " +
|
||||
"Consider accessing 'sourceSets' only on the Kotlin extension level.",
|
||||
level = DeprecationLevel.WARNING,
|
||||
replaceWith = ReplaceWith("project.kotlin.sourceSets")
|
||||
)
|
||||
val sourceSets: NamedDomainObjectContainer<KotlinSourceSet>
|
||||
}
|
||||
|
||||
+3
-2
@@ -83,8 +83,9 @@ interface KotlinTarget : Named, HasAttributes, HasProject, HasMutableExtras {
|
||||
|
||||
@Deprecated(
|
||||
"Accessing 'sourceSets' container on the Kotlin target level DSL is deprecated. " +
|
||||
"Consider configuring 'sourceSets' on the Kotlin extension level.",
|
||||
level = DeprecationLevel.WARNING
|
||||
"Consider accessing 'sourceSets' on the Kotlin extension level.",
|
||||
level = DeprecationLevel.WARNING,
|
||||
replaceWith = ReplaceWith("project.kotlin.sourceSets")
|
||||
)
|
||||
val sourceSets: NamedDomainObjectContainer<KotlinSourceSet>
|
||||
}
|
||||
|
||||
+3
-2
@@ -31,8 +31,9 @@ internal interface InternalKotlinTarget : KotlinTarget, HasMutableExtras {
|
||||
|
||||
@Deprecated(
|
||||
"Accessing 'sourceSets' container on the Kotlin target level DSL is deprecated. " +
|
||||
"Consider configuring 'sourceSets' on the Kotlin extension level.",
|
||||
level = DeprecationLevel.WARNING
|
||||
"Consider accessing 'sourceSets' on the Kotlin extension level.",
|
||||
level = DeprecationLevel.WARNING,
|
||||
replaceWith = ReplaceWith("project.kotlin.sourceSets")
|
||||
)
|
||||
override val sourceSets: NamedDomainObjectContainer<KotlinSourceSet>
|
||||
get() = project.extensions.getByType<KotlinProjectExtension>().sourceSets
|
||||
|
||||
+12
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.sources
|
||||
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginLifecycle
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
@@ -12,6 +14,7 @@ import org.jetbrains.kotlin.gradle.plugin.await
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataCompilation
|
||||
import org.jetbrains.kotlin.gradle.utils.MutableObservableSet
|
||||
import org.jetbrains.kotlin.gradle.utils.ObservableSet
|
||||
import org.jetbrains.kotlin.gradle.utils.getByType
|
||||
|
||||
internal val KotlinSourceSet.internal: InternalKotlinSourceSet
|
||||
get() = (this as? InternalKotlinSourceSet) ?: throw IllegalArgumentException(
|
||||
@@ -26,6 +29,15 @@ internal interface InternalKotlinSourceSet : KotlinSourceSet {
|
||||
|
||||
/** Configuration that resolves into sources variants of all Source Set dependencies */
|
||||
val dependencySourcesConfigurationName: String
|
||||
|
||||
@Deprecated(
|
||||
"Accessing 'sourceSets' container inside another KotlinSourceSet is deprecated. " +
|
||||
"Consider accessing 'sourceSets' only on the Kotlin extension level.",
|
||||
level = DeprecationLevel.WARNING,
|
||||
replaceWith = ReplaceWith("project.kotlin.sourceSets")
|
||||
)
|
||||
override val sourceSets: NamedDomainObjectContainer<KotlinSourceSet>
|
||||
get() = project.extensions.getByType<KotlinProjectExtension>().sourceSets
|
||||
}
|
||||
|
||||
internal suspend fun InternalKotlinSourceSet.awaitPlatformCompilations(): Set<KotlinCompilation<*>> {
|
||||
|
||||
+16
@@ -7,14 +7,30 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.unitTests
|
||||
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.InternalKotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.util.assertAllImplementationsAlsoImplement
|
||||
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class InternalKotlinSourceSetTest {
|
||||
@Test
|
||||
fun `test - all implementations of KotlinCompilation - implement InternalKotlinCompilation`() {
|
||||
assertAllImplementationsAlsoImplement(KotlinCompilation::class, InternalKotlinCompilation::class)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sourceSets inside should be equal to extension one`() {
|
||||
val project = buildProjectWithMPP {}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
val projectSourceSets = project.multiplatformExtension.sourceSets
|
||||
project.multiplatformExtension.sourceSets.forEach {
|
||||
@Suppress("DEPRECATION")
|
||||
assertEquals(projectSourceSets, it.sourceSets)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user