IDEA/Gradle Integration & Code Generation

A quick overview and then two questions...

I am working on a new project that uses Gradle as the build system of record. We are really happy with Gradle and have been astounded with its power and flexibility. We are also adopting IDEA as our IDE of choice and because we have mandated that Gradle is the build system of record we do not check in our IDEA project files. Up to this point the Gradle/IDEA integration has been smooth and wonderful (great work on the v13 improvements to Gradle Intellij folks!). Recently we introduced a feature that performs a little bit of code generation of a Java properties file. We generate this custom .properties file using a custom task and then we drop it into a generatedresources folder. We then add our custom task as a dependency of the compileJava task. This all works flawlessly in Gradle. When it comes to IDEA the generatedresources folder shows up as a "Resource Folder" but the code generation task (our custom task) is never run from IDEA unless we run it explicitly (either through the Gradle tool view or from the command-line). This leads me to my questions...

1) Is there any good documentation somewhere the explains how IDEA and Gradle inter-operate? My google searches have left me empty handed. I understand Gradle but how IDEA works with Gradle is a magic box and the curious side of me abhor's magic boxes. Perhaps if I could source some good documentation I might be able to answer my own questions. My gut tells me that IDEA uses the Gradle API to load the project structure and then uses this to generate the various IDEA project files but then IDEA kind of takes over and Gradle is no longer used (with some additional synchronization to help make life easier). If this understanding is correct then things like adding dependant tasks are likely not possible unless the IDEA project files natively support custom tasks (which I don't think they do). Caveat: I'm fairly new to both Gradle and IDEA.

2) A follow-on question from #1: Can someone provide some suggestions on how to implement various code generation stategies with Gradle/IDEA integration. At present we are just generating a property file but in the future we have a few real code generation considerations (ex. protocol buffers). I see that there is a protocol buffer's plugin so I'm wondering if the plugin route is the answer here but I am interested to see what some more experienced people have to say on the matter.

Thanks for the support!

Please sign in to leave a comment.