NoSuchMethodError: optionsBuilder.build().getService() in Google Cloud Storage

夙愿已清 提交于 2021-01-29 11:01:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!