A newbie's guide to Gradle and IDEA?

How is one supposed to create and maintain a project with Intellij and Gradle?

I couldn't find any article anywhere that puts it all together from creating the project to keeping it in synch. I'm sure such an article exists, does anyone have any pointers?

In the meantime I spent a good chunk of my day figuring out what I explain below (also available at https://peerly.codeplex.com/wikipage?title=Gradle%20and%20IDEA%20Intellij&referringTitle=Home). I can't imagine what I specify below is right or even good but it does seem to work for 12. I gave up on 13.

But again, I hope someone has a simpler solution. So links or explanations are most welcome!



IDEA Intellij 12

  1. Create a new directory to contain my project
  2. Create src/main/java to hold my source code as specified here
  3. Create a build.gradle file in the root directory using the template below
  4. Go to the command line and cd over to the directory that contains  the Intellij project. Now run the equivalent of this command for your os   "c:\Peerly\Prototype\YaronG\CouchDBJavaTest>c:\gradle-1.8\bin\gradle.bat  build idea" (and no, I'm not a big fan of screwing around with my path  hence the long form for calling gradle). If everything works then this  command will generate all appropriate IDEA project files.
  5. Now open IDEA and open file and navigate to the .ipr file, say yes  when asked if you want to open this project. I had to click on the  project name in bold in the left hand corner and select 'src' for  anything to show up.
  6. Right click on Java and add a new package with your package name
  7. Now add in your Java classes under that package
  8. File -> Settings -> Gradle, set Gradle home to the version of Gradle you downloaded
  9. View -> Tool Windows -> JetGradle. Hit 'Add' and point it to the build.gradle file.

Any time a change is made to the build.gradle file you have to run back to JetGradle and hit the refresh button under Project.

apply plugin: 'java'
apply plugin: 'idea'

repositories {

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.5'
    compile 'org.slf4j:slf4j-simple:1.7.5'


  1. File->New Project->Java->Gradle
  2. Put in a nice name for the project and hit next
  3. Hit finish
  4. I then add the two lines below to dependencies in build.gradle so I have standard logging
    compile 'org.slf4j:slf4j-api:1.7.5'
    compile 'org.slf4j:slf4j-simple:1.7.5'
  1. Oddly enough there are no source directories in the default  project. So I have to add src/main/java from the root and then right  click on java and identify it as source root
  2. Right click on Java and add a new package with your package name
  3. Now add in your Java classes under that package
  4. view->tool windows->gradle. Notice it's empty. Huh? I hit the  green + and had to navigate away from some random directory it picked to  the build.gradle file for my project. I used the defaults for the  'Import Module from Gradle' screen.
  5. Go to build.gradle and hit 'Ok, apply suggestion!' for the  suggestion to use Gradle to grab sources, good for debugging. Then  delete sourceCompatibility (which even Intellij suggests you delete!!!!)
  6. Now go back to the view->tool windows->gradle window and hit build.
  7. Double click on 'build'

This is the good news/bad news part. The build works. But  unfortunately Intellij doesn't pick up any of the dependencies from the  build.gradle so there is no autocomplete and a lot of angry red.

I have no idea why things aren't working but oh well I give up on 13 for now.

Comment actions Permalink

Hi Yaron,

Thanks for feedback, it's good idea to create a Developer Quickstart for IJ gradle integration. I will put it on the following page http://confluence.jetbrains.com/display/IDEADEV/Gradle+integration.

Meanwhile you can use the following screencasts to get overview of basic first steps:

Part1 (5 min) - http://www.screenr.com/DWkH

Part2 (4 min) - http://www.screenr.com/LWkH

Note, there was a bug in the recent EAP(IntelliJ IDEA 13 build 132.719) in the plugin, so please use EAP that should be available today.


Comment actions Permalink

Thanks for the videos! BTW, did they have any sound? But it's hard to copy and paste from a video. Still, having watched those would have saved me a bunch of time.

Also is the expectation that we should be trying to run the latest Gradle build as linked to in your page or should I just stick with JetGradle in Intellij 12?



Comment actions Permalink

yep, there is no any sound in the video.

Assembled gradle plugin of the new version for IJ 12 was intended to get early feedback from IJ 12 users about the reworked plugin and it's not actually up-to-date now. There were many changes and latest features/fixes likely not to be backported for IJ 12 anymore.

If you are planing to use the latest features of Gradle and need IDE features like codeInsight for build scripts or debug your tasks, you can try IJ 13 EAP.
But be carefull, since EAP it's not event beta version (see http://confluence.jetbrains.com/display/IDEADEV/IDEA+13+EAP).

So, for production use it's may be better to stick with IJ 12 old bundled JetGradle plugin, it's up to you ;)


Comment actions Permalink

I'll be stick with 12 since I am doing production work. I look forward to moving to 13 when it's ready. I hope for the sake of those
coming after me that something like the documentation I wrote can be released because I've literally wasted days dealing with these issues.
:( I have another thread asking some more questions but I suspect you'll end up having to answer those too so I apologize in advance. :)




Please sign in to leave a comment.