How to specify IntelliJ Exclude Directories using Gradle?

前端 未结 3 1382
轮回少年
轮回少年 2020-12-15 03:57

Using IntelliJ to open a build.gradle file, in the \"Import Project from Gradle\" window, the \"Excluded Roots\" are pre-populated with the .gradle

相关标签:
3条回答
  • 2020-12-15 04:41

    As shown in the Gradle Build Language Reference, you can configure the idea.module.excludeDirs property, which is of type List<File>. Apparently IDEA doesn't support including subdirectories of excluded directories, so you'll have to exclude all siblings of build/generated-sources. For example:

    idea {
        module {
            excludeDirs = [file(".gradle")]
            ["classes", "docs", "dependency-cache", "libs", "reports", "resources", "test-results", "tmp"].each {
                excludeDirs << file("$buildDir/$it")
            }
        }
    }
    

    If supported by the Protocol Buffer plugin, it may be easier to put the generated sources into a place outside build, and make that place known to the clean task (e.g. clean.delete "generated-sources").

    0 讨论(0)
  • 2020-12-15 04:44

    Another solution. Works with Idea 13.

    idea.module {
         excludeDirs -= file(buildDir) //1
         buildDir.listFiles({d,f->f != 'generated-sources'} as FilenameFilter).each {excludeDirs += it}} //2
    
    1. Remove buildDir from excludeDirs.
    2. Exclude each buildDir child (except generating-source).
    0 讨论(0)
  • 2020-12-15 04:55

    If you are using the Gradle Kotlin DSL, use the following snippet:

    idea {
      module {
        excludeDirs.add(file("..."))
      }
    }
    
    0 讨论(0)
提交回复
热议问题