问题
I am trying to connect to google bucket to upload a file.
StorageOptions.Builder optionsBuilder = StorageOptions.newBuilder();
optionsBuilder.setCredentials(GoogleCredentials.getApplicationDefault());
Storage storage = optionsBuilder.build().getService();
I have provided service account in environment variables and when i looked into optionsBuilder.build() the credentials are added correctly including projectId, credentials etc. but service
property is showing null.
its giving error for optionsBuilder.build().getService()
and returns
com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient$Builder.setBatchPath(Ljava/lang/String;)Lcom/google/api/client/googleapis/services/AbstractGoogleClient$Builder;
Here are the maven dependencies related to google cloud
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-datastore</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
</dependency>
Letme know if there is any workaround for it
来源:https://stackoverflow.com/questions/56236363/nosuchmethoderror-optionsbuilder-build-getservice-in-google-cloud-storage