@@ -50,14 +50,6 @@ private fun Project.configureDependencies() {
50
50
)
51
51
dependencies.add(TEST_IMPLEMENTATION_CONFIGURATION , getAtomicfuDependencyNotation(Platform .JS , version))
52
52
}
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
- }
61
53
withPluginWhenEvaluatedDependencies(" kotlin-multiplatform" ) { version ->
62
54
configureMultiplatformPluginDependencies(version)
63
55
}
@@ -96,10 +88,10 @@ private fun Project.configureTasks() {
96
88
}
97
89
98
90
private enum class Platform (val suffix : String ) {
99
- JVM (" " ),
91
+ JVM (" -jvm " ),
100
92
JS (" -js" ),
101
- NATIVE (" -native " ),
102
- COMMON ( " -common " )
93
+ NATIVE (" " ),
94
+ MULTIPLATFORM ( " " )
103
95
}
104
96
105
97
private enum class CompilationType { MAIN , TEST }
@@ -119,15 +111,8 @@ private fun String.sourceSetNameToType(): CompilationType? = when (this) {
119
111
private val Project .config: AtomicFUPluginExtension
120
112
get() = extensions.findByName(EXTENSION_NAME ) as ? AtomicFUPluginExtension ? : AtomicFUPluginExtension (null )
121
113
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 "
131
116
132
117
// Note "afterEvaluate" does nothing when the project is already in executed state, so we need
133
118
// a special check for this case
@@ -248,14 +233,29 @@ fun Project.sourceSetsByCompilation(): Map<KotlinSourceSet, List<KotlinCompilati
248
233
return sourceSetsByCompilation
249
234
}
250
235
251
- private val atomicfuRootMppModulePlatform = Platform .NATIVE
252
-
253
236
fun Project.configureMultiplatformPluginDependencies (version : String ) {
254
237
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
256
239
.getByName(KotlinSourceSet .COMMON_MAIN_SOURCE_SET_NAME )
257
240
.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
+ }
259
259
} else {
260
260
sourceSetsByCompilation().forEach { (sourceSet, compilations) ->
261
261
val platformTypes = compilations.map { it.platformType }.toSet()
@@ -265,9 +265,9 @@ fun Project.configureMultiplatformPluginDependencies(version: String) {
265
265
val compilationType = compilationNames.single().compilationNameToType()
266
266
? : return @forEach // skip unknown compilations
267
267
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"
269
269
when (platformTypes.single()) {
270
- KotlinPlatformType .common -> Platform .COMMON
270
+ KotlinPlatformType .common -> Platform .MULTIPLATFORM
271
271
KotlinPlatformType .jvm, KotlinPlatformType .androidJvm -> Platform .JVM
272
272
KotlinPlatformType .js -> Platform .JS
273
273
KotlinPlatformType .native -> Platform .NATIVE
@@ -401,12 +401,17 @@ class AtomicFUPluginExtension(pluginVersion: String?) {
401
401
402
402
@CacheableTask
403
403
open class AtomicFUTransformTask : ConventionTask () {
404
+ @PathSensitive(PathSensitivity .RELATIVE )
404
405
@InputFiles
405
406
lateinit var inputFiles: FileCollection
407
+
406
408
@OutputDirectory
407
409
lateinit var outputDir: File
410
+
411
+ @Classpath
408
412
@InputFiles
409
413
lateinit var classPath: FileCollection
414
+
410
415
@Input
411
416
var variant = " FU"
412
417
@Input
@@ -427,8 +432,10 @@ open class AtomicFUTransformTask : ConventionTask() {
427
432
428
433
@CacheableTask
429
434
open class AtomicFUTransformJsTask : ConventionTask () {
435
+ @PathSensitive(PathSensitivity .RELATIVE )
430
436
@InputFiles
431
437
lateinit var inputFiles: FileCollection
438
+
432
439
@OutputDirectory
433
440
lateinit var outputDir: File
434
441
@Input
0 commit comments