Importing a Gradle project into IntelliJ

Well, this should be easy, but as usual in practical software engineering it often is not. So, here is my recipe for importing gradle projects into IntelliJ.

Unable to find package java.lang in classpath?

On a newly installed IntelliJ, I sometimes run into a problem, namely that IntelliJ cannot compile anything, complaining that the core java.lang library is missing.

If you run into the same problem, do this:

  1. Click 'File' and then 'Project Structure...'
  2. In the dialog appearing, click 'SDK' under 'Platform Settings'.
    The list of file in the classpath is likely much shorter than the one shown above. Therefore, click the '...' button at the end of the 'JDK Home Path:'.
  3. A 'Select Home Directory for JDK' props up, just hit the 'OK' button, as this will read the directory into IntelliJ again, and thus fix the missing dependencies.

Panic Button

The standard answer in software engineering when systems behave weird is reboot. I have had to reboot intellij gradle projects quite a few times. So here is a recipe.

  1. Close the project in IntelliJ.
  2. On the Welcome screen, click the 'X' / delete icon, next to the project name. Ensure that the project is gone from the Welcome screen.
  3. Open a shell, go to the project root folder, and remove folder '.idea' and possible file '(project).iml', to ensure all IntelliJ files are deleted.
  4. Now, repeat the import procedure for the project.

Henrik Bærbak Christensen - Aarhus University