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.
Open the project, located under “java-docs-samples/translate”:
git clone https://github.com/GoogleCloudPlatform/java-docs-samples.git
At this point, you might simply try to run the application by navigating to the main method and clicking the play button:
… and configuring the input arguments to translate some text from English to French by editing the newly created run configuration:
Run the program again, and this time you get the following error:
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:
- Enable the service on your Google Cloud Platform (GCP) project
- Create a new service account with the appropriate roles for accessing the service
- Update your local run configuration with the necessary environment variables to access the service
Select the Cloud Translation API and your GCP project, and click “Add Cloud Libraries”:
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:
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:
Run the program again and your input text is successfully translated from English to French using the Cloud Translation service:
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
Cloud Tools for IntelliJ: