如何使用Gradle Kotlin DSL导入Amazon S3进行春季启动 [英] How to import amazon s3 for spring boot using gradle kotlin dsl

查看:79
本文介绍了如何使用Gradle Kotlin DSL导入Amazon S3进行春季启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试按照官方文档中的说明将s3导入到我的spring boot项目中,但相关性仍未得到解决. https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/setup-project-gradle.html

I have tried to import s3 in my spring boot project following the instructions on the official docs but the dependencies aren't being resolved. https://docs.aws.amazon.com/sdk-for-java/v2/developer-guide/setup-project-gradle.html

我将 software.amazon.awssdk:bom 从文档更新为最新的 2.7.16 ,希望可以解决此问题.

I updated the software.amazon.awssdk:bom from the documentation to the latest 2.7.16 hoping this will fix it.

这是我的build.gradle.kts文件

this is my build.gradle.kts file

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

plugins {
    kotlin("plugin.jpa") version "1.3.31"
    id("org.springframework.boot") version "2.1.5.RELEASE"
    id("io.spring.dependency-management") version "1.0.7.RELEASE"
    kotlin("jvm") version "1.3.31"
    kotlin("plugin.spring") version "1.3.31"
    kotlin("plugin.noarg") version "1.3.31"
}

allOpen {
    annotation("javax.persistence.Entity")
    annotation("javax.persistence.MappedSuperclass")
    annotation("javax.persistence.Embeddable")
}

noArg {
    annotation("javax.persistence.Entity")
}

group = "com.leaveentry"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    implementation("com.google.api-client:google-api-client:1.25.0")
    implementation("io.jsonwebtoken:jjwt-api:0.10.5")
    implementation(platform("software.amazon.awssdk:bom:2.7.16"))
    implementation("software.amazon.awssdk:s3")
    runtimeOnly("com.h2database:h2")
    runtimeOnly("mysql:mysql-connector-java")
    runtimeOnly("io.jsonwebtoken:jjwt-impl:0.10.5")
    runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.10.5")
    annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation("org.springframework.security:spring-security-test")
}

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

当我尝试导入s3相关类时,它们没有解决.

When I try to import s3 related classes, they are not resolved.

import com.amazonaws.auth.AWSStaticCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.regions.Regions
import com.amazonaws.services.s3.AmazonS3ClientBuilder
import com.amazonaws.services.s3.model.CannedAccessControlList
import com.amazonaws.services.s3.model.PutObjectRequest

推荐答案

我遇到了类似的问题,尽管我没有设法使特定版本的Amazon Bom正常工作,但我找到了解决方法.

I've had similar issues and although I didn't manage to make that specific version of amazon bom work, I found a workaround.

将以下几行添加到您的 build.gradle.kts 中:

Add to your build.gradle.kts the following lines:

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

以及 dependencies 块中的以下实现:

implementation("software.amazon.awssdk:s3:2.10.1")

注意:或者,如果要一次包含所有服务,则可以添加以下内容:

Note: Alternatively, you can add the following if you want to include all the services at once:

implementation("software.amazon.awssdk:aws-sdk-java:2.10.1")

这篇关于如何使用Gradle Kotlin DSL导入Amazon S3进行春季启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆