BrownieBrown
BrownieBrown

Reputation: 135

Kotlin Spring Gradle AWS Dependency

I am trying to set up an AmazonConfig file for my own project to get better with Spring and AWS but I can not figure out how to import the right AWS dependency for Gradle to make it work.

build.gradle.kt

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "2.4.3"
    id("io.spring.dependency-management") version "1.0.11.RELEASE"
    kotlin("jvm") version "1.4.30"
    kotlin("plugin.spring") version "1.4.30"
}

group = "mbraun"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_15

repositories {
    mavenCentral()
}

dependencyManagement {
    imports {
        mavenBom("com.amazonaws:aws-java-sdk-bom:1.11.228")
    }
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("software.amazon.awssdk:s3:2.10.1")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "15"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

AmazonConfig

package mbraun.awsimageupload.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import com.amazonaws.auth.BasicAWSCredentials

@Configuration
class AmazonConfig {
    @Bean
    fun s3(): AmazonS3 {
        val awsCredentials: AWSCredentials = BasicAWSCredentials(
            "xy",
            "xz"
        )
        return AmazonS3ClientBuilder
            .standard()
            .withCredentials(AWSStaticCredentialsProvider(awsCredentials))
            .build()
    }
}

I can not import them.

I tried: 1)https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/setup-project-gradle.html 2)How to import amazon s3 for spring boot using gradle kotlin dsl

None worked for me.

Upvotes: 0

Views: 1243

Answers (1)

smac2020
smac2020

Reputation: 10734

A discussion on how to setup a gradle file for AWS Services is located here:

https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/setup-project-gradle.html

This doc is for AWS for Java V2 (which Amazon recommends using). Follow that doc and you will learn how to setup a gradle file successfully,

If you want to learn about using a Spring Boot app and AWS, try following this document that walks you through building a Spring BOOT app that uses AWS SDK for Java V2. It then teaches you how to invoke various AWS Services and then how to deploy the sample app to the cloud.

Creating your first AWS Java web application

UPDATE Aug 2021

AWS Supports a Kotlin SDK. Details - https://aws.amazon.com/blogs/developer/aws-sdk-for-kotlin-alpha-release/

Upvotes: 1

Related Questions