To ensure high quality and to be consistent with our other Cloud libraries, the documentation for Storage Transfer Service is now using the Cloud Client Libraries instead of the Google API Client Libraries. See Client libraries explained for more information about the two options.
The Google API Client Library continues to receive updates, but is no longer referenced in the documentation.
This guide covers the main differences as they apply to using Storage Transfer Service, and provides instructions on updating your clients when migrating to the Cloud Client Library.
Java
Updating dependencies
To switch to the new library, replace your dependency on
google-api-services-storagetransfer with google-cloud-storage-transfer.
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage-transfer</artifactId>
<version>0.2.3</version>
</dependency>If you are using Gradle without BOM, add this to your dependencies:
implementation 'com.google.cloud:google-cloud-storage-transfer:0.2.3'
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>24.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage-transfer</artifactId>
</dependency>
For the most part, code can be pretty easily converted from the API Client Library to the Cloud Client Library. The following are some key differences between the two Java clients
Client instantiation
The Cloud Client Library reduces a lot of the boilerplate associated with client instantiation by handling it behind the scenes.
API Client Library
GoogleCredentials credential = GoogleCredentials.getApplicationDefault();
if (credential.createScopedRequired()) {
credential = credential.createScoped(StoragetransferScopes.all());
}
Storagetransfer storageTransfer = new Storagetransfer.Builder(Utils.getDefaultTransport(),
Utils.getDefaultJsonFactory(), new HttpCredentialsAdapter(credential))
.build();