Jump to Content
Google Cloud

Access Google Cloud services, right from IntelliJ IDEA

July 31, 2018
Etan Shaul

Software Engineer

Great news for IntelliJ users: You can now use Google Cloud services and APIs right from JetBrains’ integrated development environment (IDE). With the Cloud Tools for IntelliJ plugin, you can now discover APIs, consume them, and test against them locally, all without leaving your IDE.

The Cloud Tools plugin for IntelliJ streamlines the development process by integrating tasks into the IDE, such as enabling Google Cloud APIs, creating service accounts for local development, and adding the corresponding Java client libraries to your build.
Example: Using the Cloud Translation API with the Cloud Tools for IntelliJ plugin

Say you are interested in using the Cloud Translation API in our Java Maven-based project. If the Cloud Tools for IntelliJ plugin isn’t already configured, then first install it as described in this quickstart.

Clone the example Cloud Translation project, which allows you to translate some input text from English to French.

Loading...

Open the project, located under “java-docs-samples/translate”:

https://storage.googleapis.com/gweb-cloudblog-publish/images/1_java_docsk91x.max-500x500.PNG

At this point, you might simply try to run the application by navigating to the main method and clicking the play button:

https://storage.googleapis.com/gweb-cloudblog-publish/images/2_translate_text_playgk3h.max-700x700.PNG

… and configuring the input arguments to translate some text from English to French by editing the newly created run configuration:

https://storage.googleapis.com/gweb-cloudblog-publish/images/3_translate_textx0vd.max-700x700.PNG

Run the program again, and this time you get the following error:

https://storage.googleapis.com/gweb-cloudblog-publish/images/4_translate_text_error92or.max-700x700.PNG

As you may have already guessed, you’re missing authentication rights to access the Cloud Translation API from your local machine. To overcome this, you’d normally have to go through the following steps:

  1. Enable the service on your Google Cloud Platform (GCP) project
  2. Create a new service account with the appropriate roles for accessing the service
  3. Update your local run configuration with the necessary environment variables to access the service
Thankfully, the Cloud Tools for IntelliJ plugin can help. In IntelliJ, navigate to the Cloud Tools menu item under “Tools > Google Cloud Tools > Add Cloud libraries …”:

https://storage.googleapis.com/gweb-cloudblog-publish/images/5_google_cloud_toolsbobg.max-600x600.PNG

Select the Cloud Translation API and your GCP project, and click “Add Cloud Libraries”:

https://storage.googleapis.com/gweb-cloudblog-publish/images/6_google_cloud_translationo2in.max-700x700.PNG

In the confirmation window that appears, you can see that Cloud Tools for IntelliJ takes care of enabling the API and creating the service account for you:

https://storage.googleapis.com/gweb-cloudblog-publish/images/7_google_cloud_translation_APIn7rr.max-700x700.PNG

Lastly, select the run configuration that you created earlier so that the plugin can inject the necessary environment variables for accessing the Cloud Translation service from your local machine:

https://storage.googleapis.com/gweb-cloudblog-publish/images/8_service_account_key4vkg.max-700x700.PNG

Run the program again and your input text is successfully translated from English to French using the Cloud Translation service:

https://storage.googleapis.com/gweb-cloudblog-publish/images/9_run_text_translate18qp.max-600x600.PNG

The Cloud Tools for IntelliJ plugin also assists with the following:

  • Adding Java client libraries to your Maven pom.xml if they are not already present
  • Writing a Bill of Materials (BOM) to your pom.xml to help avoid dependency version conflicts
  • Detecting and acting on potential misconfigurations, including a missing BOM, through pom.xml file inspections with quick-fixes
The Cloud Tools for IntelliJ plugin provides many more features to help optimize your development workflow including support for Google App Engine, Stackdriver Debugger, Cloud Repositories, and Cloud Storage. For more information and to leave feedback please visit the official documentation and GitHub pages:

Cloud Tools for IntelliJ:

Posted in