diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/MetadataDependencyTransformationTask.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/MetadataDependencyTransformationTask.kt index cbe3317c7aa..465ec276f11 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/MetadataDependencyTransformationTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/MetadataDependencyTransformationTask.kt @@ -16,11 +16,7 @@ import org.gradle.api.file.ProjectLayout import org.gradle.api.file.RegularFileProperty import org.gradle.api.model.ObjectFactory import org.gradle.api.tasks.* -import org.gradle.work.NormalizeLineEndings -import org.jetbrains.kotlin.gradle.dsl.kotlinExtension import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet -import org.jetbrains.kotlin.gradle.plugin.sources.KotlinDependencyScope.* -import org.jetbrains.kotlin.gradle.plugin.sources.internal import org.jetbrains.kotlin.gradle.targets.metadata.dependsOnClosureWithInterCompilationDependencies import org.jetbrains.kotlin.gradle.tasks.dependsOn import org.jetbrains.kotlin.gradle.tasks.locateOrRegisterTask @@ -64,35 +60,13 @@ open class MetadataDependencyTransformationTask //region Task Configuration State & Inputs private val transformationParameters = GranularMetadataTransformation.Params(project, kotlinSourceSet) + @Suppress("unused") // task inputs for up-to-date checks + @get:Nested + internal val taskInputs = MetadataDependencyTransformationTaskInputs(project, kotlinSourceSet) + @get:OutputDirectory internal val outputsDir: File get() = projectLayout.kotlinTransformedMetadataLibraryDirectoryForBuild(transformationParameters.sourceSetName) - @Suppress("unused") // Gradle input - @get:InputFiles - @get:PathSensitive(PathSensitivity.RELATIVE) - @get:IgnoreEmptyDirectories - @get:NormalizeLineEndings - internal val configurationToResolve: FileCollection = kotlinSourceSet.internal.resolvableMetadataConfiguration - - @Suppress("unused") // Gradle input - @get:InputFiles - @get:PathSensitive(PathSensitivity.RELATIVE) - @get:IgnoreEmptyDirectories - @get:NormalizeLineEndings - protected val hostSpecificMetadataConfigurationsToResolve: FileCollection = project.filesProvider { - kotlinSourceSet.internal.compilations - .filter { compilation -> if (compilation is KotlinNativeCompilation) compilation.konanTarget.enabledOnCurrentHost else true } - .mapNotNull { compilation -> compilation.internal.configurations.hostSpecificMetadataConfiguration } - } - - @Transient // Only needed for configuring task inputs - private val participatingSourceSetsLazy: Lazy>? = lazy { - kotlinSourceSet.internal.withDependsOnClosure.toMutableSet().apply { - if (any { it.name == KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME }) - add(project.kotlinExtension.sourceSets.getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME)) - } - } - @Transient // Only needed for configuring task inputs private val parentTransformationTasksLazy: Lazy>>? = lazy { dependsOnClosureWithInterCompilationDependencies(kotlinSourceSet).mapNotNull { @@ -102,13 +76,6 @@ open class MetadataDependencyTransformationTask } } - private val participatingSourceSets: Set - get() = participatingSourceSetsLazy?.value - ?: error( - "`participatingSourceSets` is null. " + - "Probably it is accessed it during Task Execution with state loaded from Configuration Cache" - ) - private val parentTransformationTasks: List> get() = parentTransformationTasksLazy?.value ?: error( @@ -116,23 +83,6 @@ open class MetadataDependencyTransformationTask "Probably it is accessed it during Task Execution with state loaded from Configuration Cache" ) - @Suppress("unused") // Gradle input - @get:Input - protected val inputSourceSetsAndCompilations: Map> by lazy { - participatingSourceSets.associate { sourceSet -> - sourceSet.name to sourceSet.internal.compilations.map { it.name }.sorted() - } - } - - @Suppress("unused") // Gradle input - @get:Input - protected val inputCompilationDependencies: Map>> by lazy { - participatingSourceSets.flatMap { it.internal.compilations }.associate { - it.name to project.configurations.getByName(it.compileDependencyConfigurationName) - .allDependencies.map { listOf(it.group, it.name, it.version) }.toSet() - } - } - @get:OutputFile protected val transformedLibrariesIndexFile: RegularFileProperty = objectFactory .fileProperty() diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/MetadataDependencyTransformationTaskInputs.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/MetadataDependencyTransformationTaskInputs.kt new file mode 100644 index 00000000000..81788acf00a --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/MetadataDependencyTransformationTaskInputs.kt @@ -0,0 +1,88 @@ +package org.jetbrains.kotlin.gradle.plugin.mpp + +import org.gradle.api.Project +import org.gradle.api.artifacts.Configuration +import org.gradle.api.artifacts.ProjectDependency +import org.gradle.api.artifacts.component.ProjectComponentIdentifier +import org.gradle.api.file.FileCollection +import org.gradle.api.tasks.* +import org.gradle.work.NormalizeLineEndings +import org.jetbrains.kotlin.gradle.dsl.kotlinExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet +import org.jetbrains.kotlin.gradle.plugin.sources.internal +import org.jetbrains.kotlin.gradle.utils.filesProvider +import org.jetbrains.kotlin.utils.addToStdlib.applyIf + +internal class MetadataDependencyTransformationTaskInputs( + project: Project, + kotlinSourceSet: KotlinSourceSet, + private val skipProjectDependencies: Boolean = false, +) { + @Suppress("unused") // Gradle input + @get:InputFiles + @get:PathSensitive(PathSensitivity.RELATIVE) + @get:IgnoreEmptyDirectories + @get:NormalizeLineEndings + val configurationToResolve: FileCollection = kotlinSourceSet + .internal + .resolvableMetadataConfiguration + .applyIf(skipProjectDependencies) { withoutProjectDependencies() } + + @Suppress("unused") // Gradle input + @get:InputFiles + @get:PathSensitive(PathSensitivity.RELATIVE) + @get:IgnoreEmptyDirectories + @get:NormalizeLineEndings + val hostSpecificMetadataConfigurationsToResolve: FileCollection = project.filesProvider { + kotlinSourceSet.internal.compilations + .filter { compilation -> if (compilation is KotlinNativeCompilation) compilation.konanTarget.enabledOnCurrentHost else true } + .mapNotNull { compilation -> compilation + .internal + .configurations + .hostSpecificMetadataConfiguration + ?.applyIf(skipProjectDependencies) { withoutProjectDependencies() } + } + } + + @Transient // Only needed for configuring task inputs + private val participatingSourceSetsLazy: Lazy>? = lazy { + kotlinSourceSet.internal.withDependsOnClosure.toMutableSet().apply { + if (any { it.name == KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME }) + add(project.kotlinExtension.sourceSets.getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME)) + } + } + + private val participatingSourceSets: Set + get() = participatingSourceSetsLazy?.value + ?: error( + "`participatingSourceSets` is null. " + + "Probably it is accessed it during Task Execution with state loaded from Configuration Cache" + ) + + @Suppress("unused") // Gradle input + @get:Input + val inputSourceSetsAndCompilations: Map> by lazy { + participatingSourceSets.associate { sourceSet -> + sourceSet.name to sourceSet.internal.compilations.map { it.name }.sorted() + } + } + + @Suppress("unused") // Gradle input + @get:Input + val inputCompilationDependencies: Map>> by lazy { + participatingSourceSets.flatMap { it.internal.compilations }.associate { + it.name to project.configurations.getByName(it.compileDependencyConfigurationName) + .allDependencies + .applyIf(skipProjectDependencies) { filterNot { it is ProjectDependency } } + .map { listOf(it.group, it.name, it.version) }.toSet() + } + } +} + +private fun Configuration.withoutProjectDependencies(): FileCollection { + return incoming.artifactView { view -> + view.componentFilter { componentIdentifier -> + componentIdentifier !is ProjectComponentIdentifier + } + }.files +} diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropMetadataDependencyTransformationTask.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropMetadataDependencyTransformationTask.kt index 4a7672522af..ed1d39ba8d9 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropMetadataDependencyTransformationTask.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/native/internal/CInteropMetadataDependencyTransformationTask.kt @@ -113,7 +113,10 @@ internal open class CInteropMetadataDependencyTransformationTask @Inject constru @Transient @get:Internal val sourceSet: DefaultKotlinSourceSet, @get:OutputDirectory val outputDirectory: File, @get:Internal val cleaning: Cleaning, - objectFactory: ObjectFactory + /** when set, project-to-project dependencies will not be included to [outputLibraryFiles], + * assuming they are added during gradle configuration, see [createCInteropMetadataDependencyClasspath] for details */ + private val skipProjectDependencies: Boolean, + objectFactory: ObjectFactory, ) : DefaultTask() { private val parameters = GranularMetadataTransformation.Params(project, sourceSet) @@ -133,38 +136,8 @@ internal open class CInteropMetadataDependencyTransformationTask @Inject constru } } - @Suppress("unused") - class ChooseVisibleSourceSetProjection( - @Input val dependencyModuleIdentifiers: List, - @Nested val projectStructureMetadata: KotlinProjectStructureMetadata, - @Optional @Input val visibleSourceSetProvidingCInterops: String? - ) { - constructor(chooseVisibleSourceSets: ChooseVisibleSourceSets) : this( - dependencyModuleIdentifiers = chooseVisibleSourceSets.dependency.toKpmModuleIdentifiers(), - projectStructureMetadata = chooseVisibleSourceSets.projectStructureMetadata, - visibleSourceSetProvidingCInterops = chooseVisibleSourceSets.visibleSourceSetProvidingCInterops - ) - } - - @Suppress("unused") - @get:Classpath - protected val inputArtifactFiles: FileCollection = sourceSet - .internal - .resolvableMetadataConfiguration - .withoutProjectDependencies() - - @get:Internal - protected val chooseVisibleSourceSets - get() = sourceSet - .metadataTransformation - .metadataDependencyResolutionsOrEmpty - .resolutionsToTransform() - - @Suppress("unused") @get:Nested - protected val chooseVisibleSourceSetsProjection by lazy { - chooseVisibleSourceSets.map(::ChooseVisibleSourceSetProjection).toSet() - } + internal val inputs = MetadataDependencyTransformationTaskInputs(project, sourceSet, skipProjectDependencies) @get:OutputFile protected val outputLibrariesFileIndex: RegularFileProperty = objectFactory