Gradle – Managing project dependencies with Gradle and IntelliJ

gradleintellij-idea

I am looking to use Gradle to build my Groovy / Grails based project for which we are using IntelliJ Idea as the IDE.

I am using IntelliJ version 11.1.4, Gradle version 1.2.

My project is a configured as a multi project build with various Groovy & Grails subprojects.

I was hoping that this would give me the same kind of IDE support that I would get if managing the build through Maven, such as:

  • Automatic dependency management (import new dependencies to IntelliJ when added to various build.gradle)
  • Build DSL support
  • Execution of build tasks
  • Use of the underlying build system (gradle) by the IDE when performing builds\

I have imported my project into IntelliJ by opening the root build.gradle file.

So far I am coming up against a few annoying problems:

  1. IntelliJ is not recognising (or recognising randomly) changes to dependencies in the build.gradle files and therefore dependencies are not being updated.
  2. The gradle "idea" plugin doesn't seem to work with multi module projects.

How are people working with Gradle inside IntelliJ? Are you managing dependencies manually within IntelliJ??

Best Answer

I have been using Gradle "idea" plugin for some time now and it works very well. Since "idea" plugin simply generates IntelliJ project configuration files it is somewhat limited in what you can do with it, but nevertheless, I have had more success with it compared to the IntelliJ gradle support (JetGradle thing).

Gradle "idea" plugin does work with multi-module projects, never had a problem with that. I always put parent project configuration in master folder (see Initialization chapter), which seems to work. Never tried the nested structure though.

In order to do additional IntelliJ configuration you can do some .ipr and .iml tinkering from gradle, or alternatively try using one of my plugins (see Utilities plugin) which will do most of the tinkering for you.