View a markdown version of this page

创建项目生成文件 - AWS SDK for Kotlin

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

创建项目生成文件

配置单点登录访问权限和开发环境后,使用您的首选构建工具创建 Kotlin 项目。在生成文件中,指定您的应用程序需要访问的依赖关系。 AWS 服务

要查看所有可能的 Maven 工件名称的列表,请查阅 API 参考文档。要查找最新版本的 SDK,请查看最新版本 GitHub

以下示例生成文件提供了开始对包含七个的项目进行编码所需的元素 AWS 服务。

Gradle

AWS SDK for Kotlin 发布了 Gradle 版本目录和物料清单 (BOM),可帮助您发现依赖项的名称并使多个工件的版本号保持同步。

请注意,版本目录是 Gradle 版本 8 之前的预览功能。根据您使用的 Gradle 版本,您可能需要通过功能预览 API 选择加入。

使用 Gradle 版本目录
  1. 在您的settings.gradle.kts文件中,在versionCatalogs区块内添加一个方dependencyResolutionManagement块。

    以下示例文件配置 AWS SDK for Kotlin 版本目录。您可以导航到该X.Y.Z链接以查看可用的最新版本。

    plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "X.Y.Z" } rootProject.name = "your-project-name" dependencyResolutionManagement { repositories { mavenCentral() } versionCatalogs { create("awssdk") { from("aws.sdk.kotlin:version-catalog:X.Y.Z") } } }
  2. 使用版本目录build.gradle.kts提供的类型安全标识符在中声明依赖关系。

    以下示例文件声明了 seven 的依赖关系 AWS 服务。

    plugins { kotlin("jvm") version "X.Y.Z" application } group = "org.example" version = "1.0-SNAPSHOT" repositories { mavenCentral() } dependencies { implementation(platform(awssdk.bom)) implementation(platform("org.apache.logging.log4j:log4j-bom:X.Y.Z")) implementation(awssdk.services.s3) implementation(awssdk.services.dynamodb) implementation(awssdk.services.iam) implementation(awssdk.services.cloudwatch) implementation(awssdk.services.cognitoidentityprovider) implementation(awssdk.services.sns) implementation(awssdk.services.pinpoint) implementation("org.apache.logging.log4j:log4j-slf4j2-impl") // Test dependency. testImplementation(kotlin("test")) } tasks.test { useJUnitPlatform() } java { toolchain { languageVersion = JavaLanguageVersion.of(X*) } } application { mainClass = "org.example.AppKt" }

    * Java 版本,例如1721

Maven

以下示例pom.xml文件具有 7 的依赖关系 AWS 服务。您可以导航到该X.Y.Z链接以查看可用的最新版本。

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>setup</artifactId> <version>1.0-SNAPSHOT</version> <properties> <aws.sdk.kotlin.version>X.Y.Z</aws.sdk.kotlin.version> <kotlin.version>X.Y.Z</kotlin.version> <log4j.version>X.Y.Z</log4j.version> <junit.jupiter.version>X.Y.Z</junit.jupiter.version> <jvm.version>X*</jvm.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>aws.sdk.kotlin</groupId> <artifactId>bom</artifactId> <version>${aws.sdk.kotlin.version}</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-bom</artifactId> <version>${log4j.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>aws.sdk.kotlin</groupId> <artifactId>s3-jvm</artifactId> </dependency> <dependency> <groupId>aws.sdk.kotlin</groupId> <artifactId>dynamodb-jvm</artifactId> </dependency> <dependency> <groupId>aws.sdk.kotlin</groupId> <artifactId>iam-jvm</artifactId> </dependency> <dependency> <groupId>aws.sdk.kotlin</groupId> <artifactId>cloudwatch-jvm</artifactId> </dependency> <dependency> <groupId>aws.sdk.kotlin</groupId> <artifactId>cognitoidentityprovider-jvm</artifactId> </dependency> <dependency> <groupId>aws.sdk.kotlin</groupId> <artifactId>sns-jvm</artifactId> </dependency> <dependency> <groupId>aws.sdk.kotlin</groupId> <artifactId>pinpoint-jvm</artifactId> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j2-impl</artifactId> </dependency> <!-- Test dependencies --> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-test-junit</artifactId> <version>${kotlin.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> <version>${junit.jupiter.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <sourceDirectory>src/main/kotlin</sourceDirectory> <testSourceDirectory>src/test/kotlin</testSourceDirectory> <plugins> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <version>${kotlin.version}</version> <executions> <execution> <id>compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> </execution> <execution> <id>test-compile</id> <phase>test-compile</phase> <goals> <goal>test-compile</goal> </goals> </execution> </executions> <configuration> <jvmTarget>${jvm.version}</jvmTarget> </configuration> </plugin> </plugins> </build> </project>

* Java 版本,例如1721