[GRADLE-1174] The IdeaPlugin defines all of $buildDir as excluded Created: 15/Oct/10  Updated: 04/Jan/13  Resolved: 16/Mar/12

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Steve Ebersole Assignee: Szczepan Faber
Resolution: Not A Bug Votes: 0


The IdeaPlugin defines all of $buildDir as excluded which messes up attempts to use, for example, generated sources such as from Antlr which writes to $buildDir/generated-src/antlr/.

Therefore declarations such as

ideaModule {
    sourceDirs.add( file( '$buildDir/generated-src/antlr/main' ) )

have no effect

Comment by Szczepan Faber [ 04/Apr/11 ]

I think following workarounds should help:

ideaModule {
    //manipulate the default excludeDirs:
    excludeDirs -= "someFolderIDontWantToExclude"
    //or prepare your own list of excludeDirs:
    excludeDirs = [project.file('.gradle'), "$project.buildDir/excludeMe"] as Set
Comment by Steve Ebersole [ 04/Apr/11 ]

Thus far I have tried the following unsuccessfully:

  1. excludeDirs -= "target"
  2. excludeDirs -= project.buildDir
  3. excludeDirs -= project.buildDirName
  4. excludeDirs -= project.file( "target" )

So what is the magic incantation for that? (we override buildDir to target)

Comment by Steve Ebersole [ 04/Apr/11 ]

Heck, I even tried the other form and Gradle is still excluding buildDir:

excludeDirs = [
] as Set

So this is obviously controlled "elsewhere, elusive".

Comment by Szczepan Faber [ 05/Apr/11 ]

It's because the idea/eclipse tasks are trying to merge new settings to the existing config files. Either of the workarounds should work given that you delete the *.iml file beforehand or run 'cleanIdeaModule'. Watch out not to run 'cleanIdea' because it wipes all configs, including workspace settings (*.iws) that may contain some useful stuff (like shelved changes, bookmarks, copyright profiles etc.)

You can disable merging exclude dirs so that devs don't have to delete the *.imls behorehand using beforeConfigured/whenConfigured hooks:

ideaModule { 
    beforeConfigured { module ->
        //applied after content read from file 
        //but before merging with info from build.gradle

More about beforeConfigured/whenConfigured hooks is in the guide

Comment by Steve Ebersole [ 11/Apr/11 ]

Just so I am clear... If there are existing exludes found, Gradle decides to "merge" by excluding the entire build dir rather than merging the individual directories?

This is not a case, for example, where I have previously had the build dir excluded and Gradle is just merging into that setup. No, it is actively deciding to exclude all of build dir.

Comment by Szczepan Faber [ 11/Apr/11 ]

>If there are existing exludes found, Gradle decides to "merge" by excluding the entire build dir rather than merging the individual directories?

Here's how merging works: the exclude folders are kept in a Set. When ideaModule task executes it reads the existing *.iml contents and feeds the set with currently configured excludes. Then the user's customizations (ideaModule.excludeDirs) from build.gradle are added to that set. Does it match the behavior you observe?

Comment by Steve Ebersole [ 11/Apr/11 ]

No, not at all.

I have initially a properly "adjusted" IntelliJ project. When I try to run gradle idea against that I end up with build dir (target in my case) as an exclude.

Btw, not sure why or how it fits in, but manually clearing the excludes 'beforeConfigured' does seem to work.

Comment by Szczepan Faber [ 11/Apr/11 ]

Ok, I already cloned hibernate-core, I will take closer look and let you know

Comment by Szczepan Faber [ 12/Apr/11 ]

Steve, take a look at my fork of hibernate-core:


If you have questions we can discuss using github code review features

Comment by Szczepan Faber [ 22/Jul/11 ]

I'd like to close this issue because I'm not sure what needs to be fixed Here's the summary of excluded dirs behavior of idea plugin (as of today):

  • by default the 'build' and '.gradle' folders are excluded
  • one can configure exclude dirs with: idea.module.excludeDirs = [ file('foo'), file('bar') ]
  • GenerateIdeaModule task will merge the existing excludes found in the *.iml file with the excludes configured by idea.module.excludeDirs. To avoid merging you can run 'cleanIdeaModule' or use workaround mentioned in my earlier post.
Comment by Szczepan Faber [ 16/Mar/12 ]

If that's ok I'm closing this issue. Please see my previous comment.

Generated at Wed Jun 30 11:48:52 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.