Run Configurations
IntelliJ with Bazel

Run Configurations


In all IntelliJ IDEs, you run and debug your application binaries and tests using run configurations, which specify what target to run and a variety of options for how to run that target.

Bazel run configurations are different from normal IntelliJ run configurations because they are organized around Bazel targets (rather than "modules" and "variants"). Run configurations are managed and launched from this collection of widgets at the top of the IDE:

IntelliJ with Bazel Run Configurations

Run configurations created by default

The IDE automatically creates run configurations for supported targets explicitly listed in your project view (not pulled in by an :all or /...:all expression). If most of your team builds, launches, and debugs the same few android_binary targets, you should probably add those targets to a checked-in .bazelproject file.

Run configurations for all other targets must be created manually.

Creating a run configuration manually

To create a run configuration (or edit existing configurations), go to the run configuration dropdown and click Edit Configurations...

IntelliJ with Bazel Edit Configurations

ASwB Android binary

  1. Add/delete/copy a configuration.
  2. Select the Bazel Command run configuration type. This works for all types of targets (Android/Java/generic). The UI and options will vary depending on the target type.
  3. Select the target you want to run/debug.
  4. Customize the launch settings as you see fit. For binaries, you can pick activity launch settings. For tests, you can add test filters. For configurations delegating to Bazel, you can add flags. androidbinary and androidtest targets share a large number of device-oriented settings.
  5. IntelliJ loves confirmations, so you get two! Your changes are not saved until you click OK or Apply.

Creating and running test configurations with right-click menu

You can quickly create supported test configurations by right-clicking on classes and methods. The tests in the corresponding Bazel test target will be filtered to only run the tests in the target class, or to only run that test method.

  1. Right click on a class (in the project view, the structure view, the file tabs, or in a source file), or a method (in the structure view or a source file), or a test target in a BUILD file.
  2. Go to Create a Run Configuration, Run or Debug (to create a run configuration or immediately launch it).
  3. Select the type of test target as appropriate. If you pick the wrong kind of test, it will fail.

You can re-run the same configuration by launching it from the top of the IDE or right-clicking on the same class or method.

Right click test

Note: If your bazel target is missing from your project view, try File > Edit Project View... > Save and Sync.

Note: Improved button icon submissions are welcome!