Run targets remotely (Gradle, Rust)
For certain run/debug configurations, you can run your code in another environment such as cloud or a Docker container directly from CLion.
This feature allows you to instantly test the changes against the real environment the app is intended for. This ensures that there will be no incompatibilities when moving to production, which is especially important when working on code that depends on the environment. This feature also spares you the extra actions normally required to deploy and run the app every time something changes.
Prerequisites
The environment used for running the app is referred to as target. For CLion to run code on a target, the target has to define a language runtime, which represents something on the target that can be used by a run/debug configuration to run code.
In order to run your code on a target, all you need is to define the target execution environment in the run/debug configuration that you would normally use for local run. After you have done that, launching the app on a target is no different than launching it locally.
Supported run/debug configuration types
The following run/debug configurations can run on a remote target:
Create a run/debug configuration
Go to
. Alternatively, press Alt+Shift+F10, then 0.In the Run/Debug Configuration dialog, click the Add button on the toolbar or press Alt+Insert. The list shows the run/debug configuration templates.
Select one of the supported run/debug configuration types.
If you have already defined the target, select it from the Run on menu. Otherwise, click Manage targets to add a new target. For more information on configuring a particular target type, refer to the following procedures:
You can also configure a run target in a run/debug configuration template, so the next time you create a new configuration of that type, its parameters already have the desired values. For more information, refer to Configure the default values for a template.
Run
Procedure for running the app on a remote target is the same as for running it locally:
Select the run/debug configuration on the main toolbar.
Click or press Shift+F10.
CLion builds the artifacts and then copies them to the target. After that, it runs the app on the target using the specified runtime.
Target types
A target describes the configuration of the environment in which the application will run.
When you create a remote target, CLion automatically detects the runtimes available in the remote environment. If required, you can manually configure additional runtimes.
SSH
Select if you want to use an existing SSH configuration or create a new one:
Select an existing SSH configuration from the SSH list, then click Next. For more information about configuring SSH, refer to Create SSH configurations.
Enter the IP of the SSH server, the port listening for SSH connections, and the name of the user on the server machine, on whose behalf you are going to run your application. Click Next.
Wait for the connection to be established. If there is an agent that has the credentials, no additional configuration will be required. Otherwise, select the authentication method and provide the required values:
Password: enter the password.
Key pair (OpenSSH or PuTTY): To apply this authentication method, you must have a private key on the client machine and a public key on the remote server. CLion supports private keys that are generated with the OpenSSH utility.
Specify the path to the file where your private key is stored and type the passphrase (if any) in the corresponding fields. To have CLion remember the passphrase, select the Save passphrase checkbox.
Click Next.
Wait for the SSH server introspection to complete. During this step, CLion tries to identify the language runtimes available in the environment. Click Next.
Configure the following properties:
Use rsync: toggle this option to use rsync for file transfer. This is recommended as it will generally speed up copying files.
Project path on target: the path on the server that will be used for storing the project files.
Add language runtimes . For each runtime, specify its version and path on the server. The configured settings then appear in the Build and run section of the run/debug configuration when you select this environment as the target.
The following runtimes are available:
Java: a JDK on the server suitable for running your application. When this runtime type is selected, the application is built locally and then copied to the destination
Maven: Maven installed on the server. When this runtime type is selected, the sources and libraries are copied to the server, and then built and run there.
Docker
Select or configure a Docker server as described in Enable Docker support.
For Windows and macOS – make sure Docker has access to all the folders used in the workflow, for example, the project folder, .maven, and so on. For more information, refer to official Docker documentation.
Select if you want to build an image locally or pull it from Docker registry.
Dockerfile: the Dockerfile that will be used for building the image.
Context folder: a folder whose contents will be accessible by the Docker daemon during the build to be later used in the image filesystem.
Rebuild image automatically every time before running code: when this option is set, the image will be rebuilt every time the code is run. Otherwise, CLion will use the already existing image (if any).
Additionally, you can specify the following:
Image tag: specify the name and tag for the built image. Similar to using the
-t
option withdocker build
.Build options: specify arbitrary options for the
docker build
command.Build args: override the default build-time variables. Similar to using the
--build-arg
option withdocker build
.Run options: specify arbitrary options for the
docker run
command.
Image tag: specify the full coordinates for the image to be pulled from a registry. The default
:latest
tag will be used if only repository is specified.Run options: specify arbitrary options for the
docker run
command.
Wait for the container introspection to complete. During this step, CLion tries to identify the language runtimes available in the environment. Click Next.
If required, configure language runtimes. You may need it in when:
you have a complex image (for example with several JDK). The primary runtime will be identified automatically. However, any additional runtimes require manual configuration.
the introspection fails. In most cases, CLion will correctly identify the primary runtime based on the context from step 1. If this does not happen, manually modify the primary runtime.
For each runtime, specify its version and path in the container. The configured runtimes then appear in the Build and run section of the run/debug configuration when you select this environment as the target.
The following runtimes are available:
Java: a JDK suitable for running your application. When this runtime type is selected, the application is built locally and then copied to the destination
Maven: Maven in the container. When this runtime type is selected, the sources and libraries are copied to the container, and then built and run there.
Docker Compose
You can use a single Docker Compose service as a run target.
Select or configure a Docker server as described in Enable Docker support.
For Windows and macOS – make sure Docker has access to all the folders used in the workflow, for example, the project folder, .maven, and so on. For more information, refer to official Docker documentation.
Specify the Docker Compose configuration files, select the necessary service, and provide any additional environment variables. Click Next.
Wait for the Docker Compose service introspection to complete. During this step, CLion tries to identify the language runtimes available in the environment. Click Next.
If necessary, configure language runtimes. This may be necessary in the following cases:
If you have a complex service with several runtimes, CLion will identify the primary one automatically. However, any additional runtimes require manual configuration.
If the introspection fails, modify the primary runtime manually.
For each runtime, specify its version and path in the container. The configured runtimes then appear in the Build and run section of the run/debug configuration when you select this environment as the target.
The following runtimes are available:
Java: If there is a Java runtime available in the container, the application is built locally and then copied to the target.
Maven and Gradle: If there is Maven or Gradle in the container, the sources and libraries are copied to the container, and then built and run there.