@@ -69,69 +69,55 @@ ksp {
6969 arg(" op-allowlist" , allowlist.joinToString(" ;" ))
7070}
7171
72- if (project.NATIVE_ENABLED ) {
73- // Configure KSP for multiplatform: https://kotlinlang.org/docs/ksp-multiplatform.html
74- // https://github.com/google/ksp/issues/963#issuecomment-1894144639
75- // https://github.com/google/ksp/issues/965
76- dependencies.kspCommonMainMetadata(project(" :hll:dynamodb-mapper:dynamodb-mapper-ops-codegen" ))
77-
78- kotlin.sourceSets.commonMain {
79- tasks.withType<KspTaskMetadata > {
80- // Wire up the generated source to the commonMain source set
81- kotlin.srcDir(destinationDirectory)
82- }
83- }
84- } else {
85- // FIXME This is a dirty hack for JVM-only builds which KSP doesn't consider to be "multiplatform". Explanation of
86- // hack follows in narrative, minimally-opinionated comments.
87-
88- // Start by invoking the JVM-only KSP configuration
89- dependencies.kspJvm(project(" :hll:dynamodb-mapper:dynamodb-mapper-ops-codegen" ))
90-
91- // Then we need to move the generated source from jvm to common
92- val moveGenSrc by tasks.registering {
93- // Can't move src until the src is generated
94- dependsOn(tasks.named(" kspKotlinJvm" ))
95-
96- // Detecting these paths programmatically is complex; just hardcode them
97- val srcDir = file(" build/generated/ksp/jvm/jvmMain" )
98- val destDir = file(" build/generated/ksp/common/commonMain" )
99-
100- inputs.dir(srcDir)
101- outputs.dirs(srcDir, destDir)
102-
103- doLast {
104- if (destDir.exists()) {
105- // Clean out the existing destination, otherwise move fails
106- require(destDir.deleteRecursively()) { " Failed to delete $destDir before moving from $srcDir " }
107- } else {
108- // Create the destination directories, otherwise move fails
109- require(destDir.mkdirs()) { " Failed to create path $destDir " }
110- }
72+ // FIXME This is a dirty hack for JVM-only builds which KSP doesn't consider to be "multiplatform". Explanation of
73+ // hack follows in narrative, minimally-opinionated comments.
11174
112- Files .move(srcDir.toPath(), destDir.toPath(), StandardCopyOption .REPLACE_EXISTING )
113- }
114- }
75+ // Start by invoking the JVM-only KSP configuration
76+ dependencies.kspJvm(project(" :hll:dynamodb-mapper:dynamodb-mapper-ops-codegen" ))
77+
78+ // Then we need to move the generated source from jvm to common
79+ val moveGenSrc by tasks.registering {
80+ // Can't move src until the src is generated
81+ dependsOn(tasks.named(" kspKotlinJvm" ))
82+
83+ // Detecting these paths programmatically is complex; just hardcode them
84+ val srcDir = file(" build/generated/ksp/jvm/jvmMain" )
85+ val destDir = file(" build/generated/ksp/common/commonMain" )
86+
87+ inputs.dir(srcDir)
88+ outputs.dirs(srcDir, destDir)
11589
116- listOf (" jvmSourcesJar" , " metadataSourcesJar" , " jvmProcessResources" ).forEach {
117- tasks.named(it) {
118- dependsOn(moveGenSrc)
90+ doLast {
91+ if (destDir.exists()) {
92+ // Clean out the existing destination, otherwise move fails
93+ require(destDir.deleteRecursively()) { " Failed to delete $destDir before moving from $srcDir " }
94+ } else {
95+ // Create the destination directories, otherwise move fails
96+ require(destDir.mkdirs()) { " Failed to create path $destDir " }
11997 }
98+
99+ Files .move(srcDir.toPath(), destDir.toPath(), StandardCopyOption .REPLACE_EXISTING )
120100 }
101+ }
121102
122- tasks.withType<KotlinCompilationTask <* >> {
123- if (this !is KspTaskJvm ) {
124- // Ensure that any **non-KSP** compile tasks depend on the generated src move
125- dependsOn(moveGenSrc)
126- }
103+ listOf (" jvmSourcesJar" , " metadataSourcesJar" , " jvmProcessResources" ).forEach {
104+ tasks.named(it) {
105+ dependsOn(moveGenSrc)
127106 }
107+ }
128108
129- // Finally, wire up the generated source to the commonMain source set
130- kotlin.sourceSets.commonMain {
131- kotlin.srcDir(" build/generated/ksp/common/commonMain/kotlin" )
109+ tasks.withType<KotlinCompilationTask <* >> {
110+ if (this !is KspTaskJvm ) {
111+ // Ensure that any **non-KSP** compile tasks depend on the generated src move
112+ dependsOn(moveGenSrc)
132113 }
133114}
134115
116+ // Finally, wire up the generated source to the commonMain source set
117+ kotlin.sourceSets.commonMain {
118+ kotlin.srcDir(" build/generated/ksp/common/commonMain/kotlin" )
119+ }
120+
135121open class DynamoDbLocalInstance : DefaultTask () {
136122 private var port: Int by Delegates .notNull()
137123
0 commit comments