@@ -29,7 +29,6 @@ import com.autonomousapps.internal.utils.toJson
2929import com.autonomousapps.model.DuplicateClass
3030import com.autonomousapps.model.source.AndroidSourceKind
3131import com.autonomousapps.model.source.JvmSourceKind
32- import com.autonomousapps.model.source.KmpSourceKind
3332import com.autonomousapps.model.source.SourceKind
3433import com.autonomousapps.services.GlobalDslService
3534import com.autonomousapps.services.InMemoryCache
@@ -43,7 +42,9 @@ import org.gradle.api.tasks.SourceSetContainer
4342import org.gradle.api.tasks.TaskProvider
4443import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
4544import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
45+ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
4646import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
47+ import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
4748import java.util.concurrent.atomic.AtomicBoolean
4849
4950private const val APPLICATION_PLUGIN = " application"
@@ -185,7 +186,7 @@ internal class ProjectPlugin(private val project: Project) {
185186 logger.log(" Adding Kotlin Multiplatform tasks to ${project.path} " )
186187 isKmpProject = true
187188 checkKgpOnClasspath()
188- configureKotlinKmpProject ()
189+ configureKotlinMultiplatformProject ()
189190 }
190191 pluginManager.withPlugin(JAVA_PLUGIN ) {
191192 configureJavaAppProject(maybeAppProject = true )
@@ -689,66 +690,31 @@ internal class ProjectPlugin(private val project: Project) {
689690 }
690691 }
691692
692- /* *
693- * Has the `org.jetbrains.kotlin.multiplatform` plugin applied.
694- *
695- * TODO(tsr)!!: this is currently identical to `configureKotlinJvmProject()`!!
696- */
697- private fun Project.configureKotlinKmpProject () {
698- val k = KotlinSources (this , dagpExtension)
699-
700- configureRedundantJvmPlugin {
701- it.withKotlin(k.hasKotlin)
702- }
703-
704- if (configuredForKotlinJvmOrJavaLibrary.getAndSet(true )) {
705- logger.info(" (dependency analysis) $path was already configured for the java-library plugin" )
706- redundantJvmPlugin.configure()
707- return
708- }
709-
710- val kotlin = extensions.getByType(KotlinMultiplatformExtension ::class .java)
711- val kotlinTargets = kotlin.targets
712- kotlinTargets.configureEach { target ->
713- println (" CONFIGURING KOTLIN TARGET ${target.name} " )
714- // try {
715- // val hasAbi = true
716- //
717- // val dependencyAnalyzer = KmpProjectAnalyzer(
718- // project = this,
719- // sourceSet = kmpSourceSet,
720- // hasAbi = hasAbi,
721- // )
722- // } catch (_: UnknownTaskException) {
723- // logger.warn("Skipping tasks creation for KMP target `${target.name}`")
724- // }
725- }
726-
727- k.kotlinSourceSets.forEach { sourceSet ->
728- try {
729- val sourceKind = KmpSourceKind .of(sourceSet.name)
730- val hasAbi = hasAbi(sourceSet)
731- val kmpSourceSet = KmpSourceSet (sourceSet, sourceKind)
693+ /* * Has the [KOTLIN_MULTIPLATFORM_PLUGIN] plugin applied. */
694+ private fun Project.configureKotlinMultiplatformProject () {
695+ extensions.getByType(KotlinMultiplatformExtension ::class .java)
696+ .targets
697+ .withType(KotlinJvmTarget ::class .java) // TODO(tsr) delete? or only analyze jvm targets? what about android targets?
698+ .configureEach { target ->
699+ println (" CONFIGURING KOTLIN TARGET ${target.name} " ) // TODO delete
700+ target.compilations.configureEach { compilation ->
701+ println (" CONFIGURING KOTLIN COMPILATION ${compilation.name} " ) // TODO delete
702+ try {
703+ val hasAbi = hasAbi(compilation)
704+ val kmpSourceSet = KmpSourceSet (compilation)
705+
706+ val dependencyAnalyzer = KmpProjectAnalyzer (
707+ project = this ,
708+ sourceSet = kmpSourceSet,
709+ hasAbi = hasAbi,
710+ )
732711
733- val dependencyAnalyzer = if (hasAbi) {
734- KmpProjectAnalyzer (
735- project = this ,
736- sourceSet = kmpSourceSet,
737- hasAbi = true ,
738- )
739- } else {
740- KmpProjectAnalyzer (
741- project = this ,
742- sourceSet = kmpSourceSet,
743- hasAbi = false ,
744- )
712+ analyzeDependencies(dependencyAnalyzer)
713+ } catch (_: UnknownTaskException ) {
714+ logger.warn(" Skipping tasks creation for KMP target `${target.name} `" )
715+ }
745716 }
746-
747- analyzeDependencies(dependencyAnalyzer)
748- } catch (_: UnknownTaskException ) {
749- logger.warn(" Skipping tasks creation for sourceSet `${sourceSet.name} `" )
750717 }
751- }
752718 }
753719
754720 private fun Project.hasAbi (sourceSet : SourceSet ): Boolean {
@@ -765,17 +731,20 @@ internal class ProjectPlugin(private val project: Project) {
765731 return hasApiConfiguration && isNotTest && isNotMainApp
766732 }
767733
768- private fun Project.hasAbi (sourceSet : KotlinSourceSet ): Boolean {
769- if (sourceSet.name in dagpExtension.abiHandler.exclusionsHandler.excludedSourceSets.get()) {
734+ private fun Project.hasAbi (compilation : KotlinCompilation <* >): Boolean {
735+ val sourceSetName = compilation.defaultSourceSet.name
736+ if (sourceSetName in dagpExtension.abiHandler.exclusionsHandler.excludedSourceSets.get()) {
770737 // if this sourceSet is user-excluded, then it doesn't have an ABI
771738 return false
772739 }
773740
774- val hasApiConfiguration = configurations.findByName(sourceSet.apiConfigurationName) != null
741+ // TODO(tsr): not sure about the equality checks against `KotlinSourceSet...`
742+ // what about this? `compilation.name == KotlinCompilation.MAIN_COMPILATION_NAME`
743+ val hasApiConfiguration = configurations.named(compilation.apiConfigurationName) != null
775744 // The 'test' sourceSet does not have an ABI
776- val isNotTest = sourceSet.name != KotlinSourceSet .COMMON_TEST_SOURCE_SET_NAME
745+ val isNotTest = sourceSetName != KotlinSourceSet .COMMON_TEST_SOURCE_SET_NAME
777746 // The 'main' sourceSet for an app project does not have an ABI
778- val isNotMainApp = ! (isAppProject() && sourceSet.name == KotlinSourceSet .COMMON_MAIN_SOURCE_SET_NAME )
747+ val isNotMainApp = ! (isAppProject() && sourceSetName == KotlinSourceSet .COMMON_MAIN_SOURCE_SET_NAME )
779748 return hasApiConfiguration && isNotTest && isNotMainApp
780749 }
781750
0 commit comments