Skip to content

Commit 9b182c0

Browse files
committed
Fix KMP builds
1 parent a8c7a2c commit 9b182c0

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

hll/dynamodb-mapper/dynamodb-mapper/build.gradle.kts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import aws.sdk.kotlin.gradle.kmp.NATIVE_ENABLED
77
import com.amazonaws.services.dynamodbv2.local.main.ServerRunner
88
import com.amazonaws.services.dynamodbv2.local.server.DynamoDBProxyServer
9+
import com.google.devtools.ksp.gradle.KspAATask
910
import com.google.devtools.ksp.gradle.KspTaskJvm
10-
import com.google.devtools.ksp.gradle.KspTaskMetadata
1111
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
1212
import java.nio.file.Files
1313
import java.nio.file.StandardCopyOption
@@ -67,16 +67,39 @@ ksp {
6767
}
6868

6969
if (project.NATIVE_ENABLED) {
70-
// Configure KSP for commonMain source generation; https://github.com/google/ksp/issues/963#issuecomment-1894144639
70+
// Configure KSP for multiplatform: https://kotlinlang.org/docs/ksp-multiplatform.html
71+
// https://github.com/google/ksp/issues/963#issuecomment-1894144639
72+
dependencies {
73+
add("kspCommonMainMetadata", project(":hll:dynamodb-mapper:dynamodb-mapper-ops-codegen"))
74+
}
7175

72-
dependencies.kspCommonMainMetadata(project(":hll:dynamodb-mapper:dynamodb-mapper-ops-codegen"))
76+
tasks.withType<KotlinCompilationTask<*>>().all {
77+
if(name != "kspCommonMainKotlinMetadata") {
78+
dependsOn("kspCommonMainKotlinMetadata")
79+
}
80+
}
7381

74-
kotlin.sourceSets.commonMain {
75-
tasks.withType<KspTaskMetadata> {
76-
// Wire up the generated source to the commonMain source set
77-
kotlin.srcDir(destinationDirectory)
82+
tasks.withType<KspAATask>().configureEach {
83+
if(name != "kspCommonMainKotlinMetadata") {
84+
dependsOn("kspCommonMainKotlinMetadata")
7885
}
7986
}
87+
88+
tasks.named("sourcesJar") {
89+
dependsOn("kspCommonMainKotlinMetadata")
90+
}
91+
92+
tasks.named("linuxX64SourcesJar") {
93+
dependsOn("kspCommonMainKotlinMetadata")
94+
}
95+
96+
tasks.named("jvmSourcesJar") {
97+
dependsOn("kspCommonMainKotlinMetadata")
98+
}
99+
100+
kotlin.sourceSets.commonMain {
101+
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
102+
}
80103
} else {
81104
// FIXME This is a dirty hack for JVM-only builds which KSP doesn't consider to be "multiplatform". Explanation of
82105
// hack follows in narrative, minimally-opinionated comments.

hll/dynamodb-mapper/dynamodb-mapper/common/src/aws/sdk/kotlin/hll/dynamodbmapper/values/scalars/TextConverters.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public object TextConverters {
1818
/**
1919
* Converts between [CharArray] and [String]
2020
*/
21-
public val CharArrayToStringConverter: Converter<CharArray, String> = Converter(::String, String::toCharArray)
21+
public val CharArrayToStringConverter: Converter<CharArray, String> = Converter(CharArray::concatToString, String::toCharArray)
2222

2323
/**
2424
* Converts between [Char] and [String]

hll/dynamodb-mapper/dynamodb-mapper/common/test/aws/sdk/kotlin/hll/dynamodbmapper/expressions/KeyFilterTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import aws.sdk.kotlin.hll.dynamodbmapper.items.ItemConverter
1010
import aws.sdk.kotlin.hll.dynamodbmapper.items.ItemSchema
1111
import aws.sdk.kotlin.hll.dynamodbmapper.items.KeySpec
1212
import aws.sdk.kotlin.hll.dynamodbmapper.model.Item
13-
import org.junit.jupiter.api.assertThrows
1413
import kotlin.test.Test
1514
import kotlin.test.assertEquals
15+
import kotlin.test.assertFailsWith
1616

1717
class KeyFilterTest {
1818
private val singleKeySchema = ItemSchema(DummyConverter, KeySpec.String("primary"))
@@ -31,7 +31,7 @@ class KeyFilterTest {
3131
fun testSingleKeySchemaWithErroneousSortKey() {
3232
val kf = KeyFilter("foo") { sortKey eq 2 }
3333

34-
assertThrows<IllegalArgumentException> {
34+
assertFailsWith<IllegalArgumentException> {
3535
kf.toExpression(singleKeySchema)
3636
}
3737
}

hll/dynamodb-mapper/dynamodb-mapper/common/test/aws/sdk/kotlin/hll/dynamodbmapper/values/ValueConvertersTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package aws.sdk.kotlin.hll.dynamodbmapper.values
77
import aws.sdk.kotlin.hll.dynamodbmapper.util.attr
88
import aws.sdk.kotlin.hll.dynamodbmapper.util.dynamicAttr
99
import aws.sdk.kotlin.services.dynamodb.model.AttributeValue
10+
import kotlin.jvm.JvmName
1011
import kotlin.test.assertContentEquals
1112
import kotlin.test.assertEquals
1213
import kotlin.test.assertTrue

hll/dynamodb-mapper/dynamodb-mapper/common/test/aws/sdk/kotlin/hll/dynamodbmapper/values/scalars/ScalarConvertersTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ScalarConvertersTest : ValueConvertersTest() {
1818
@Test
1919
fun testByteArrayConverter() = given(ByteArrayConverter) {
2020
byteArrayOf() inDdbIs theSame
21-
"Foo".toByteArray() inDdbIs theSame
21+
"Foo".encodeToByteArray() inDdbIs theSame
2222
ByteArray(1024) { it.toByte() } inDdbIs theSame
2323
}
2424

0 commit comments

Comments
 (0)