Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. To import the ONOS project, simply open IntelliJ and select: Import Bazel Project from the welcome screen if it's your first time using Intellij. Otherwise select File > Import Bazel Project.
  2. The next window asks you for the Bazel Workspace, click on the three dots (...) on the right, navigate to the ONOS folder and select it, the path should appear in the widows' box. Press Next.
  3. The next window asks you to Select a project view. Here you need to select a .bazelproject file, see the next section to create one, then press Next.
  4. Select Finish to import the ONOS project.

...

ONOS is not shipped with an existing .bazelproject file, for this reason, we will need to create one. This file defines which part of the source tree IntelliJ needs to be aware of and how. When importing a project in IntelliJ, you can choose the option Create from scratch, which will generate a generic configuration that looks like this:

...

Essentially, here we tell IntelliJ to import ALL directories and ALL Bazel targets (//...). Since ONOS is quite a big project, importing all targets for the first time can take more than 20 minutes depending on your configuration. UnfortunatellyUnfortunately, this .bazelproject configuration will make the IDE build and import many targets that are not need needed for development (such as OSGi and test coverage artificatsartifacts).

Generate a minimal .bazelproject file (

...

recommended)

To reduce the number of imported targets and to speed - up the import process we have created a tool to auto-generate a minimal .bazelproject file for ONOS that imports only the targets needed for Java development. To auto-generate a .bazelproject file when importing ONOS for the first time in IntelliJ:

...

This tool creates a project files file that imports the relevant targets available in ONOS at the time the tool is executed. If you create a new app/library in ONOS, or if you checkout check out a different branch with different targets, you might want to update your existing .bazelproject file to reflect the changes:

...

To load the new .bazelproject file and re-sync your project, in the top menu select Bazel > Sync > Sync project with BUILD files. It should take only a few seconds to re-sync the project after the first import.

...

If your import fails with the error Error:Cannot run program "bazel" (in directory ): error=2, No such file or directory, ite  it means IntelliJ did not properly pick-up the location of the Bazel binary and we need to change it. 

  1. Go into Intellij IDEA > Preferences > Bazel Settings
  2. Under Bazel Binary Location click on click on the three dots (...) on the right and select the location you installed Bazel in ( e.g. /usr/local/bin/bazel). You can also type the Bazel path. 
  3. Re-start the import process by re-syncing the project, in the top menu select Bazel > Sync > Sync project with BUILD files

...