In a kotlin script, trying to use the AWS SDK results in an error when trying to import the packages
#!/usr/bin/env kotlin
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
@file:DependsOn("aws.sdk.kotlin:dynamodb:0.30.1-beta")
import kotlinx.coroutines.*
import aws.sdk.kotlin.services.dynamodb.DynamoDbClient
import aws.sdk.kotlin.services.dynamodb.model.ListTablesRequest
runBlocking {
val ddb = DynamoDbClient.fromEnvironment()
println("starting")
}
results in this error
test.main.kts:7:8: error: unresolved reference: aws
import aws.sdk.kotlin.services.dynamodb.DynamoDbClient
^
test.main.kts:8:8: error: unresolved reference: aws
import aws.sdk.kotlin.services.dynamodb.model.ListTablesRequest
^
the Kotlin coroutine import works but I can't figure out why the AWS import doesn't
I've tried to use a @file:DependsOn with a non-existing sdk version to make sure that resolving the dependency works and it fails as expected so I know the script is resolving and installing the AWS SDK successfully.
The problem is related to this issue:
Using gradle or maven this change is transparent to consumers but for scripts you need to use the -jvm artifacts like
@file:DependsOn("aws.sdk.kotlin:dynamodb-jvm:0.32.5-beta")
instead of
@file:DependsOn("aws.sdk.kotlin:dynamodb:0.32.5-beta")