The IDEA module is smart about adding the project’s build directory as an exclusion directory when buliding the .iml file.
However, it is very common when doing various kinds of preprocessing (such as CoffeeScript compilation) to output into a sub-folder of the build directory. I then need some boilerplate to have the new folder appear:
idea.module.iml.whenMerged { module -> module.excludeFolders.removeAll { it.canonicalUrl.endsWith "/build" } }
Ideally, the IdeaModule task would be smart enough to exclude each folder under build, except for those that are explicitly in the SourceSetOutput directory list.