Search code examples
google-cloud-platformgcloud

How to use gcloud commands programmatically via - Java


Is there an option to use gcloud commands programmatically via - Java? I see not all of the google provided libraries have all the functionalities that are present as part of gcloud command.


Solution

  • Ugh :-(

    You're correct but there's a better solution.

    Please see this explanation: https://cloud.google.com/apis/docs/client-libraries-explained

    I discourage you from shelling out to calling the gcloud commands from Java to solve your problem and from attempting to make the calls directly.

    In summary:

    All of Google's services are available for all of the supported languages using the older client libraries called the API Client Libraries. The API Client Libraries are machine-generated and mostly guaranteed to perfectly reflect the underlying services: https://developers.google.com/api-client-library/

    For Google Cloud Platform, a newer (better) set of client libraries is available but, these have required hand-coding. It's not a good excuse but, because of this, these libraries have lagged their underlying services. The lag includes some services not being available in some languages, some methods of some services not being available etc. https://cloud.google.com/apis/docs/cloud-client-libraries

    So, this creates a few challenges but...

    If you require one set of libraries for everything, go API Client Libraries

    Otherwise:

    1. If the Cloud Client Library is available, use it.
    2. If the Cloud Client Library is not available, use the API Client Library.