Wednesday, March 31, 2010

Gradle and IntelliJ IDEA

Now that I'm playing with Gradle a bit, I needed to have a way to have it play nice with my current IDE of choice, IntelliJ IDEA. At the moment IntelliJ does not support a project built by Gradle, as it does one that is built with Maven2 using a pom.xml file. But alas, using some tricks it is pretty simple.

Though IntelliJ does not support Gradle buildfiles, and vice-versa Gradle does not generate an IntelliJ project definition (yet), we can use the Eclipse integration that both provide. You can set it up in the following way. In your build.gradle file, add the eclipse plugin:

defaultTasks 'build'
usePlugin 'java'
usePlugin 'eclipse'

repositories {

dependencies {
testCompile "org.junit:junit:4.7"

If you now type "gradle eclipse", gradle will generate an Eclipse ".project" and ".classpath" file for you. Each time you run "gradle eclipse", these two will get refreshed.

Now go to IntelliJ IDEA. Instead of importing the project as a "new project", we choose "Open Project"

Now browse to your project, click the ".project" file and click "open"

Presto you're done. Now everytime gradle re-generates the classpath file, your IntelliJ project is kept in sync.

No comments:

Post a Comment