@@ -50,14 +50,6 @@ private fun Project.configureDependencies() {
5050 )
5151 dependencies.add(TEST_IMPLEMENTATION_CONFIGURATION , getAtomicfuDependencyNotation(Platform .JS , version))
5252 }
53- withPluginWhenEvaluatedDependencies(" kotlin-native" ) { version ->
54- dependencies.add(IMPLEMENTATION_CONFIGURATION , getAtomicfuDependencyNotation(Platform .NATIVE , version))
55- dependencies.add(TEST_IMPLEMENTATION_CONFIGURATION , getAtomicfuDependencyNotation(Platform .NATIVE , version))
56- }
57- withPluginWhenEvaluatedDependencies(" kotlin-platform-common" ) { version ->
58- dependencies.add(COMPILE_ONLY_CONFIGURATION , getAtomicfuDependencyNotation(Platform .COMMON , version))
59- dependencies.add(TEST_IMPLEMENTATION_CONFIGURATION , getAtomicfuDependencyNotation(Platform .COMMON , version))
60- }
6153 withPluginWhenEvaluatedDependencies(" kotlin-multiplatform" ) { version ->
6254 configureMultiplatformPluginDependencies(version)
6355 }
@@ -96,10 +88,10 @@ private fun Project.configureTasks() {
9688}
9789
9890private enum class Platform (val suffix : String ) {
99- JVM (" " ),
91+ JVM (" -jvm " ),
10092 JS (" -js" ),
101- NATIVE (" -native " ),
102- COMMON ( " -common " )
93+ NATIVE (" " ),
94+ MULTIPLATFORM ( " " )
10395}
10496
10597private enum class CompilationType { MAIN , TEST }
@@ -119,15 +111,8 @@ private fun String.sourceSetNameToType(): CompilationType? = when (this) {
119111private val Project .config: AtomicFUPluginExtension
120112 get() = extensions.findByName(EXTENSION_NAME ) as ? AtomicFUPluginExtension ? : AtomicFUPluginExtension (null )
121113
122- private fun getAtomicfuDependencyNotation (platform : Platform , version : String ): String {
123- val suffix = when (platform) {
124- // in common source sets, use a dependency on the MPP root module:
125- Platform .COMMON -> atomicfuRootMppModulePlatform.suffix
126- else -> platform.suffix
127- }
128- return " org.jetbrains.kotlinx:atomicfu$suffix :$version "
129- }
130-
114+ private fun getAtomicfuDependencyNotation (platform : Platform , version : String ): String =
115+ " org.jetbrains.kotlinx:atomicfu${platform.suffix} :$version "
131116
132117// Note "afterEvaluate" does nothing when the project is already in executed state, so we need
133118// a special check for this case
@@ -248,14 +233,29 @@ fun Project.sourceSetsByCompilation(): Map<KotlinSourceSet, List<KotlinCompilati
248233 return sourceSetsByCompilation
249234}
250235
251- private val atomicfuRootMppModulePlatform = Platform .NATIVE
252-
253236fun Project.configureMultiplatformPluginDependencies (version : String ) {
254237 if (rootProject.findProperty(" kotlin.mpp.enableGranularSourceSetsMetadata" ).toString().toBoolean()) {
255- val configurationName = project.extensions.getByType(KotlinMultiplatformExtension ::class .java).sourceSets
238+ val mainConfigurationName = project.extensions.getByType(KotlinMultiplatformExtension ::class .java).sourceSets
256239 .getByName(KotlinSourceSet .COMMON_MAIN_SOURCE_SET_NAME )
257240 .compileOnlyConfigurationName
258- dependencies.add(configurationName, getAtomicfuDependencyNotation(atomicfuRootMppModulePlatform, version))
241+ dependencies.add(mainConfigurationName, getAtomicfuDependencyNotation(Platform .MULTIPLATFORM , version))
242+
243+ val testConfigurationName = project.extensions.getByType(KotlinMultiplatformExtension ::class .java).sourceSets
244+ .getByName(KotlinSourceSet .COMMON_TEST_SOURCE_SET_NAME )
245+ .implementationConfigurationName
246+ dependencies.add(testConfigurationName, getAtomicfuDependencyNotation(Platform .MULTIPLATFORM , version))
247+
248+ // For each source set that is only used in Native compilations, add an implementation dependency so that it
249+ // gets published and is properly consumed as a transitive dependency:
250+ sourceSetsByCompilation().forEach { (sourceSet, compilations) ->
251+ val isSharedNativeSourceSet = compilations.all {
252+ it.platformType == KotlinPlatformType .common || it.platformType == KotlinPlatformType .native
253+ }
254+ if (isSharedNativeSourceSet) {
255+ val configuration = sourceSet.implementationConfigurationName
256+ dependencies.add(configuration, getAtomicfuDependencyNotation(Platform .MULTIPLATFORM , version))
257+ }
258+ }
259259 } else {
260260 sourceSetsByCompilation().forEach { (sourceSet, compilations) ->
261261 val platformTypes = compilations.map { it.platformType }.toSet()
@@ -265,9 +265,9 @@ fun Project.configureMultiplatformPluginDependencies(version: String) {
265265 val compilationType = compilationNames.single().compilationNameToType()
266266 ? : return @forEach // skip unknown compilations
267267 val platform =
268- if (platformTypes.size > 1 ) Platform .COMMON else // mix of platform types -> "common"
268+ if (platformTypes.size > 1 ) Platform .MULTIPLATFORM else // mix of platform types -> "common"
269269 when (platformTypes.single()) {
270- KotlinPlatformType .common -> Platform .COMMON
270+ KotlinPlatformType .common -> Platform .MULTIPLATFORM
271271 KotlinPlatformType .jvm, KotlinPlatformType .androidJvm -> Platform .JVM
272272 KotlinPlatformType .js -> Platform .JS
273273 KotlinPlatformType .native -> Platform .NATIVE
@@ -401,12 +401,17 @@ class AtomicFUPluginExtension(pluginVersion: String?) {
401401
402402@CacheableTask
403403open class AtomicFUTransformTask : ConventionTask () {
404+ @PathSensitive(PathSensitivity .RELATIVE )
404405 @InputFiles
405406 lateinit var inputFiles: FileCollection
407+
406408 @OutputDirectory
407409 lateinit var outputDir: File
410+
411+ @Classpath
408412 @InputFiles
409413 lateinit var classPath: FileCollection
414+
410415 @Input
411416 var variant = " FU"
412417 @Input
@@ -427,8 +432,10 @@ open class AtomicFUTransformTask : ConventionTask() {
427432
428433@CacheableTask
429434open class AtomicFUTransformJsTask : ConventionTask () {
435+ @PathSensitive(PathSensitivity .RELATIVE )
430436 @InputFiles
431437 lateinit var inputFiles: FileCollection
438+
432439 @OutputDirectory
433440 lateinit var outputDir: File
434441 @Input
0 commit comments