Using the SDK with Gradle - AWS SDK for Java

Using the SDK with Gradle

To manage SDK dependencies for your Gradle project, import the Maven BOM for the AWS SDK for Java into the build.gradle file.

Note

In the following examples, replace 1.11.X in the build file with a valid version of the AWS SDK for Java. Find the latest version in the AWS SDK for Java 1.11.x Reference.

Project setup for Gradle 4.6 or higher

Since Gradle 4.6, you can use Gradle’s improved POM support feature for importing bill of materials (BOM) files by declaring a dependency on a BOM.

To configure the AWS SDK for Java for Gradle 4.6 or later

  1. If you’re using Gradle 5.0 or later, skip to step 2. Otherwise, enable the IMPROVED_POM_SUPPORT feature in the settings.gradle file.

    enableFeaturePreview('IMPROVED_POM_SUPPORT')
  2. Add the BOM to the dependencies section of the build.gradle file.

    ... dependencies { implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.X') // Declare individual SDK dependencies without version ... }
  3. Specify the SDK modules to use in the dependencies section. For example, the following includes a dependency for Amazon Simple Storage Service (Amazon S3).

    ... dependencies { implementation 'com.amazonaws:aws-java-sdk-s3' ... }

Gradle automatically resolves the correct version of your SDK dependencies by using the information from the BOM.

The following is an example of a complete build.gradle file that includes a dependency for Amazon S3.

group 'aws.test' version '1.0-SNAPSHOT' apply plugin: 'java' sourceCompatibility = 1.8 repositories { mavenCentral() } dependencies { implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.X') implementation 'com.amazonaws:aws-java-sdk-s3' testCompile group: 'junit', name: 'junit', version: '4.11' }
Note

In the previous example, replace the dependency for Amazon S3 with the dependencies of the AWS services you will use in your project. The modules (dependencies) that are managed by the AWS SDK for Java BOM are listed on Maven central repository (https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-bom/latest).

Project setup for Gradle versions earlier than 4.6

Gradle versions earlier than 4.6 lack native BOM support. To manage AWS SDK for Java dependencies for your project, use Spring’s dependency management plugin for Gradle to import the Maven BOM for the SDK.

To configure the SDK for Gradle versions earlier than 4.6

  1. Add the dependency management plugin to your build.gradle file.

    buildscript { repositories { mavenCentral() } dependencies { classpath "io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE" } } apply plugin: "io.spring.dependency-management"
  2. Add the BOM to the dependencyManagement section of the file.

    dependencyManagement { imports { mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.X' } }
  3. Specify the SDK modules that you’ll use in the dependencies section. For example, the following includes a dependency for Amazon S3.

    dependencies { compile 'com.amazonaws:aws-java-sdk-s3' }

Gradle automatically resolves the correct version of your SDK dependencies by using the information from the BOM.

The following is an example of a complete build.gradle file that includes a dependency for Amazon S3.

group 'aws.test' version '1.0' apply plugin: 'java' sourceCompatibility = 1.8 repositories { mavenCentral() } buildscript { repositories { mavenCentral() } dependencies { classpath "io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE" } } apply plugin: "io.spring.dependency-management" dependencyManagement { imports { mavenBom 'com.amazonaws:aws-java-sdk-bom:1.11.X' } } dependencies { compile 'com.amazonaws:aws-java-sdk-s3' testCompile group: 'junit', name: 'junit', version: '4.11' }
Note

In the previous example, replace the dependency for Amazon S3 with the dependencies of the AWS service you will use in your project. The modules (dependencies) that are managed by the AWS SDK for Java BOM are listed on Maven central repository (https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-bom/latest).

For more information about specifying SDK dependencies by using the BOM, see Using the SDK with Apache Maven.