[Guide] Using IntelliJ for Robot Projects

Introduction

IntelliJ is a Java Integrated Development Environment (IDE) created by Jetbrains, the core program is used to create numerous enterprise java projects, including Android apps. IntelliJ is vastly superior to VSCode’s linting, auto-correct, navigation, features, etc.

Why does WPILib not support IntelliJ?

WPILib requires that it’s “IDE” support both C++ and Java, which the Jetbrains IDEs do not (the C++ one (Clion) is not free). Also Jetbrains extension format is absolutely garbage even in comparison to Eclipse’s.

Creating the Robot Project

This is where the dependency is required. You can either use VSCode to create the robot project, or copy a template from the GradleRIO repo. If you do attempt to do it manually, please note that are various configuration files you’ll need to edit, I won’t be going into that. I’ll assume you used VSCode to create your robot project. This tutorial assumes you used the WPILibInstaller to install all of the required dependencies.

Vendordeps

Just use VSCode to import vendor dependencies, it’s probably the easiest. However you can drop the appropriate vendor json in the vendordeps folder if you so wish.

Importing the Robot Project into IntelliJ

This is where the fun begins. Go ahead and open up IntelliJ. You’ll want to first select Open

You’ll then want to navigate to wherever your robot project is stored and select the folder.

image

You’ll know want to configure IntelliJ to point to Java (JDK) 11. Go ahead and click on File -> Project Structure.

Now you’ll want to select New -> JDK

Then you’ll want to navigate to the frcXXXX (where XXXX is the year) directory. By default this is located at C:\Users\Public\frc2019\jdk. Note that for the 2020 season, this will change to C:\Users\Public\wpilib\2020\jdk.

image

Lastly, you should change the project language level to 11. Then select Apply then Ok.

At this point, Intellisense should just work out of the box.

Building/Deploying a Robot Project

Of course, simply using the IDE to write the code isn’t enough. You’ll probably want to deploy your code to an actual robot. Let’s create the task.

In the top right window of IntelliJ, select Add Configuration.

image

Then press the + icon, and scroll down and click Gradle.

Name your project “Gradle Deploy” and then click the folder icon next to the gradle project input box. Select your gradle project.

Type in “deploy” in the tasks bar, and select the “deploy” task. Then click Apply and then Ok.

At this point, you’re all done! Simply select the green arrow in the top right point of IntelliJ to deploy your task!

image

Additional Notes

This tutorial is not supported by WPILib in any way.

Questions

What IntelliJ theme are you using? I’m using the Material Design IntelliJ theme with the slim buttons option selected.

IntelliJ randomly stopped working!!! You probably messed up the steps. Repeat the tutorial. If you’re sure you know what you were doing, select Invalidate Caches/Restart from the top left menu underneath File.

Feel free to comment any questions below.

18 Likes

Thanks for this guide!
Is it possible to debug code running on a real robot with IntelliJ IDEA?

It is. Taken from some internal documentation I wrote a year ago (may not be completely up-to-date with IntelliJ but the concept of creating a Remote configuration still holds)

  1. Make sure to be using GradleRIO version ≥2018.01.06

  2. In your build.gradle, just below where it says “roboRIO(“roborio”) {”, write “debug = true” (without the outer quotes)

  3. Deploy your code normally. The driver station will say “no robot code.” This is normal.

  4. Open the drop-down in the top right and select “Edit Run/Debug Configurations”

  5. Click the + sign and select Remote from the list

  6. Name it “Remote Robot Debug” or something, it doesn’t matter

  7. Set host to “roborio-<TEAMNUMBER>-frc.local” and port to 8348

  8. In the “search sources using module’s classpath” dropdown select “<your project name>_main”

  9. Click OK

  10. Select your debug configuration from the top right dropdown and click the bug right next to it (or press Ctrl-D).

5 Likes

Big fan of this guide! I was too lazy to try to figure out how to use IntelliJ myself, but this guide even has pictures! I hope it works, as I love my Jetbrains products. Thank you so much!

If I install vendor libraries in VSCode, will IntelliJ recognize them?

Thank you! So we should be able to use breakpoints and all the features in IntelliJ’s debugger?

You don’t need to use VSCode, you can use the WPILib Utility: https://github.com/wpilibsuite/GradleRIO/tree/v2019.2.1#without-vscode

1 Like

Should be able to, yes. Breakpoints in running robot code that deals with motors etc. may cause somewhat weird behavior, so be careful.

That sound awesome. Hopefully we will be able to use the debugger to speed up our code testing process. Thank you!

Yes, it should. You can also just put the .json files in the vendordeps folder.

We found that one of the major benefits to IntilliJ is that it had built-in JavaFX support with JDK11. We could setup different run profiles very quickly and debug different things on our custom UI’s from within IntelliJ.

We couldn’t do this in Eclipse for some reason (JDK11 seemed to mess Eclipse up a bit), and we couldn’t get proper realtime compile errors for UI-related code in VSCode. Maybe things have changed since February though.

Assuming your using Gradle, the IDE shouldn’t matter (unless your using FXML). Even then, SceneBuilder is a standalone application that you download from the internet to modify FXML layout files.

I’ve written a JavaFX application called GrizzlyTime which is a Java8/Java 11 based GUI application that hooks into Google Sheets to log members hours/dates/gender/etc.

Not quite related to this thread but you should just need to create a “Main” launcher class that launches your application. Your build.gradle should look something like this.

1 Like

We did something like that with our UI project. However, it seems like the multi-project setup we had in Gradle is what confused VS code the most.

We wanted a way to de-bug things in real time, rather than waiting for a console output. So the IDE features were helpful.

I find the debugger in IntelliJ to give a lot better visibility than VSCode. I put together some notes on remote debugging: https://firstmncsa.org/2019/01/01/debugging-java-remote-debugging/#intellij

2 Likes

As an alternative to the methodologies presented here, I publish an (unofficial) FRC Plugin for IntelliJ IDEA that includes a New Project Wizard for FRC Robot Projects. For more information see the topic IntelliJ IDEA FRC Plugin Update Released