# Class IdeaModule

java.lang.Object
org.gradle.plugins.ide.idea.model.IdeaModule

public abstract class IdeaModule extends Object
Enables fine-tuning module details (*.iml file) of the IDEA plugin.

Example of use with a blend of most possible properties. Typically you don't have to configure this model directly because Gradle configures it for you.

    plugins {
        id 'java'
        id 'idea'
    }

    //for the sake of this example, let's introduce a 'performanceTestCompile' configuration
    configurations {
      performanceTestCompile
      performanceTestCompile.extendsFrom(testCompile)
    }

    dependencies {
      //performanceTestCompile "some.interesting:dependency:1.0"
    }

    idea {

      //if you want parts of paths in resulting files (*.iml, etc.) to be replaced by variables (Files)
      pathVariables GRADLE_HOME: file('~/cool-software/gradle')

      module {
        //if for some reason you want to add an extra sourceDirs
        sourceDirs += file('some-extra-source-folder')

        //and some extra test source dirs
        testSources.from(file('some-extra-test-dir'))

        //and some extra resource dirs
        resourceDirs += file('some-extra-resource-dir')

        //and some extra test resource dirs
        testResources.from(file('some-extra-test-resource-dir'))

        //and hint to mark some of existing source dirs as generated sources
        generatedSourceDirs += file('some-extra-source-folder')

        //and some extra dirs that should be excluded by IDEA
        excludeDirs += file('some-extra-exclude-dir')

        //if you don't like the name Gradle has chosen
        name = 'some-better-name'

        //if you prefer different output folders
        inheritOutputDirs = false
        outputDir = file('muchBetterOutputDir')
        testOutputDir = file('muchBetterTestOutputDir')

        //if you prefer different SDK than the one inherited from IDEA project
        jdkName = '1.6'

        //put our custom test dependencies onto IDEA's TEST scope
        scopes.TEST.plus += [ configurations.performanceTestCompile ]

        //if 'content root' (as IDEA calls it) of the module is different
        contentRoot = file('my-module-content-root')

        //if you love browsing Javadoc
        downloadJavadoc = true

        //and hate reading sources :)
        downloadSources = false
      }
    }

For tackling edge cases, users can perform advanced configuration on the resulting XML file. It is also possible to affect the way the IDEA plugin merges the existing configuration via beforeMerged and whenMerged closures.

beforeMerged and whenMerged closures receive a `Module` parameter

Examples of advanced configuration:

    plugins {
        id 'java'
        id 'idea'
    }

    idea {
      module {
        iml {
          //if you like to keep *.iml in a secret folder
          generateTo = file('secret-modules-folder')

          //if you want to mess with the resulting XML in whatever way you fancy
          withXml {
            def node = it.asNode()
            node.appendNode('iLoveGradle', 'true')
            node.appendNode('butAlso', 'I find increasing pleasure tinkering with output *.iml contents. Yeah!!!')
          }

          //closure executed after *.iml content is loaded from existing file
          //but before gradle build information is merged
          beforeMerged { module ->
            //if you want skip merging exclude dirs
            module.excludeFolders.clear()
          }

          //closure executed after *.iml content is loaded from existing file
          //and after gradle build information is merged
          whenMerged { module ->
            //you can tinker with Module
          }
        }
      }
    }

Since:
  1.0

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected IdeaLanguageLevel`
  `languageLevel`
  The language level.
  `protected JavaVersion`
  `targetBytecodeVersion`
  The target bytecode version.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `IdeaModule(Project project, IdeaModuleIml iml)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `File`
  `getContentRoot()`
  The content root directory of the module.
  `Set<File>`
  `getExcludeDirs()`
  Directories to be excluded.
  `Set<File>`
  `getGeneratedSourceDirs()`
  The directories containing the generated sources (both production and test sources).
  `IdeaModuleIml`
  `getIml()`
  Deprecated.
  Will be removed in Gradle 10.
  `Boolean`
  `getInheritOutputDirs()`
  If true, output directories for this module will be located below the output directory for the project; otherwise, they will be set to the directories specified by `getOutputDir()` and `getTestOutputDir()`.
  `String`
  `getJdkName()`
  The JDK to use for this module.
  `IdeaLanguageLevel`
  `getLanguageLevel()`
  The module specific language Level to use for this module.
  `String`
  `getName()`
  Configures module name, that is the name of the *.iml file.
  `File`
  `getOutputDir()`
  The output directory for production classes.
  `File`
  `getOutputFile()`
  Configures output *.iml file.
  `PathFactory`
  `getPathFactory()`
  Deprecated.
  Will be removed in Gradle 10.
  `Map<String,File>`
  `getPathVariables()`
  Deprecated.
  Will be removed in Gradle 10.
  `Project`
  `getProject()`
  An owner of this IDEA module.
  `Set<File>`
  `getResourceDirs()`
  The directories containing resources.
  `Map<String, Map<String, Collection<Configuration>>>`
  `getScopes()`
  The keys of this map are the IDEA scopes.
  `Map<String, Iterable<File>>`
  `getSingleEntryLibraries()`
  Returns the single entry libraries.
  `Set<File>`
  `getSourceDirs()`
  The directories containing the production sources.
  `JavaVersion`
  `getTargetBytecodeVersion()`
  The module specific bytecode version to use for this module.
  `File`
  `getTestOutputDir()`
  The output directory for test classes.
  `abstract ConfigurableFileCollection`
  `getTestResources()`
  The complete and up-to-date collection of test resource directories.
  `abstract ConfigurableFileCollection`
  `getTestSources()`
  The complete and up-to-date collection of test source directories
  `void`
  `iml(Closure closure)`
  Deprecated.
  Will be removed in Gradle 10.
  `void`
  `iml(Action<? super IdeaModuleIml> action)`
  Deprecated.
  Will be removed in Gradle 10.
  `boolean`
  `isDownloadJavadoc()`
  Whether to download and add javadoc associated with the dependency jars.
  `boolean`
  `isDownloadSources()`
  Whether to download and add sources associated with the dependency jars.
  `boolean`
  `isOffline()`
  If true then external artifacts (e.g.
  `void`
  `mergeXmlModule(Module xmlModule)`
  Deprecated.
  Will be removed in Gradle 10.
  `Set<Dependency>`
  `resolveDependencies()`
  Resolves and returns the module's dependencies.
  `void`
  `setContentRoot(File contentRoot)`
  Sets the content root.
  `void`
  `setDownloadJavadoc(boolean downloadJavadoc)`
  Sets the download javadoc.
  `void`
  `setDownloadSources(boolean downloadSources)`
  Sets the download sources.
  `void`
  `setExcludeDirs(Set<File> excludeDirs)`
  Sets the exclude dirs.
  `void`
  `setGeneratedSourceDirs(Set<File> generatedSourceDirs)`
  Sets the generated source dirs.
  `void`
  `setInheritOutputDirs(Boolean inheritOutputDirs)`
  Sets the inherit output dirs.
  `void`
  `setJdkName(String jdkName)`
  Sets the jdk name.
  `void`
  `setLanguageLevel(IdeaLanguageLevel languageLevel)`
  Sets the language level.
  `void`
  `setName(String name)`
  Sets the name.
  `void`
  `setOffline(boolean offline)`
  Sets the offline.
  `void`
  `setOutputDir(File outputDir)`
  Sets the output dir.
  `void`
  `setOutputFile(File newOutputFile)`
  Sets the output file.
  `void`
  `setPathFactory(PathFactory pathFactory)`
  Deprecated.
  Will be removed in Gradle 10.
  `void`
  `setPathVariables(Map<String,File> pathVariables)`
  Deprecated.
  Will be removed in Gradle 10.
  `void`
  `setResourceDirs(Set<File> resourceDirs)`
  Sets the directories containing resources.
  `void`
  `setScopes(Map<String, Map<String, Collection<Configuration>>> scopes)`
  Sets the scopes.
  `void`
  `setSingleEntryLibraries(Map<String, Iterable<File>> singleEntryLibraries)`
  Sets the single entry libraries.
  `void`
  `setSourceDirs(Set<File> sourceDirs)`
  Sets the source dirs.
  `void`
  `setTargetBytecodeVersion(JavaVersion targetBytecodeVersion)`
  Sets the target bytecode version.
  `void`
  `setTestOutputDir(File testOutputDir)`
  Sets the test output dir.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### languageLevel

    protected IdeaLanguageLevel languageLevel
    The language level.
    Since:
      8.6

  - ### targetBytecodeVersion

    protected JavaVersion targetBytecodeVersion
    The target bytecode version.
    Since:
      8.6

- ## Constructor Details

  - ### IdeaModule

    @Inject public IdeaModule(Project project, IdeaModuleIml iml)

- ## Method Details

  - ### getName

    public String getName()
    Configures module name, that is the name of the *.iml file.

    It's optional because the task should configure it correctly for you. By default it will try to use the project.name or prefix it with a part of a project.path to make sure the module name is unique in the scope of a multi-module build. The 'uniqueness' of a module name is required for correct import into IDEA and the task will make sure the name is unique.

    since 1.0-milestone-2

    If your project has problems with unique names it is recommended to always run `gradle idea` from the root, i.e. for all subprojects. If you run the generation of the IDEA module only for a single subproject then you may have different results because the unique names are calculated based on IDEA modules that are involved in the specific build run.

    If you update the module names then make sure you run `gradle idea` from the root, e.g. for all subprojects, including generation of IDEA project. The reason is that there may be subprojects that depend on the subproject with amended module name. So you want them to be generated as well because the module dependencies need to refer to the amended project name. Basically, for non-trivial projects it is recommended to always run `gradle idea` from the root.

    For example see docs for `IdeaModule`

    Since:
      1.0

  - ### setName

    public void setName(String name)
    Sets the name.
    Since:
      1.0

  - ### getSourceDirs

    public Set<File> getSourceDirs()
    The directories containing the production sources. For example see docs for `IdeaModule`
    Since:
      1.0

  - ### setSourceDirs

    public void setSourceDirs(Set<File> sourceDirs)
    Sets the source dirs.
    Since:
      1.0

  - ### getGeneratedSourceDirs

    public Set<File> getGeneratedSourceDirs()
    The directories containing the generated sources (both production and test sources).

    For example see docs for `IdeaModule`

    Since:
      2.2

  - ### setGeneratedSourceDirs

    public void setGeneratedSourceDirs(Set<File> generatedSourceDirs)
    Sets the generated source dirs.
    Since:
      2.2

  - ### getScopes

    public Map<String, Map<String, Collection<Configuration>>> getScopes()
    The keys of this map are the IDEA scopes. Each key points to another map that has two keys, plus and minus. The values of those keys are collections of `Configuration` objects. The files of the plus configurations are added minus the files from the minus configurations. See example below...

    Example how to use scopes property to enable 'performanceTestCompile' dependencies in the output *.iml file:

        plugins {
            id 'java'
            id 'idea'
        }

        configurations {
          performanceTestCompile
          performanceTestCompile.extendsFrom(testCompile)
        }

        dependencies {
          //performanceTestCompile "some.interesting:dependency:1.0"
        }

        idea {
          module {
            scopes.TEST.plus += [ configurations.performanceTestCompile ]
          }
        }

    Since:
      1.0

  - ### setScopes

    public void setScopes(Map<String, Map<String, Collection<Configuration>>> scopes)
    Sets the scopes.
    Since:
      1.0

  - ### isDownloadSources

    public boolean isDownloadSources()
    Whether to download and add sources associated with the dependency jars. Defaults to true.

    For example see docs for `IdeaModule`

    Since:
      1.0

  - ### setDownloadSources

    public void setDownloadSources(boolean downloadSources)
    Sets the download sources.
    Since:
      1.0

  - ### isDownloadJavadoc

    public boolean isDownloadJavadoc()
    Whether to download and add javadoc associated with the dependency jars. Defaults to false.

    For example see docs for `IdeaModule`

    Since:
      1.0

  - ### setDownloadJavadoc

    public void setDownloadJavadoc(boolean downloadJavadoc)
    Sets the download javadoc.
    Since:
      1.0

  - ### getContentRoot

    public File getContentRoot()
    The content root directory of the module.

    For example see docs for `IdeaModule`

    Since:
      1.0

  - ### setContentRoot

    public void setContentRoot(File contentRoot)
    Sets the content root.
    Since:
      1.0

  - ### getTestSources

    public abstract ConfigurableFileCollection getTestSources()
    The complete and up-to-date collection of test source directories
    Returns:
      lazily configurable collection of test source directories
    Since:
      7.4

  - ### getResourceDirs

    public Set<File> getResourceDirs()
    The directories containing resources.

    For example see docs for `IdeaModule`

    Since:
      4.7

  - ### setResourceDirs

    public void setResourceDirs(Set<File> resourceDirs)
    Sets the directories containing resources.

    For example see docs for `IdeaModule`

    Since:
      4.7

  - ### getTestResources

    public abstract ConfigurableFileCollection getTestResources()
    The complete and up-to-date collection of test resource directories.
    Returns:
      lazily configurable collection of test resource directories
    Since:
      7.4

  - ### getExcludeDirs

    public Set<File> getExcludeDirs()
    Directories to be excluded.

    For example see docs for `IdeaModule`

    Since:
      1.0

  - ### setExcludeDirs

    public void setExcludeDirs(Set<File> excludeDirs)
    Sets the exclude dirs.
    Since:
      1.0

  - ### getInheritOutputDirs

    public Boolean getInheritOutputDirs()
    If true, output directories for this module will be located below the output directory for the project; otherwise, they will be set to the directories specified by `getOutputDir()` and `getTestOutputDir()`.

    For example see docs for `IdeaModule`

    Since:
      1.0

  - ### setInheritOutputDirs

    public void setInheritOutputDirs(Boolean inheritOutputDirs)
    Sets the inherit output dirs.
    Since:
      1.0

  - ### getOutputDir

    public File getOutputDir()
    The output directory for production classes. If `null`, no entry will be created.

    For example see docs for `IdeaModule`

    Since:
      1.0

  - ### setOutputDir

    public void setOutputDir(File outputDir)
    Sets the output dir.
    Since:
      1.0

  - ### getTestOutputDir

    public File getTestOutputDir()
    The output directory for test classes. If `null`, no entry will be created.

    For example see docs for `IdeaModule`

    Since:
      1.0

  - ### setTestOutputDir

    public void setTestOutputDir(File testOutputDir)
    Sets the test output dir.
    Since:
      1.0

  - ### getPathVariables

    @Deprecated public Map<String,File> getPathVariables()
    Deprecated.
    Will be removed in Gradle 10.
    The variables to be used for replacing absolute paths in the iml entries. For example, you might add a `GRADLE_USER_HOME` variable to point to the Gradle user home dir.

    For example see docs for `IdeaModule`

    Since:
      1.0

  - ### setPathVariables

    @Deprecated public void setPathVariables(Map<String,File> pathVariables)
    Deprecated.
    Will be removed in Gradle 10.
    Sets the path variables.
    Since:
      1.0

  - ### getJdkName

    public String getJdkName()
    The JDK to use for this module. If `null`, the value of the existing or default ipr XML (inherited) is used. If it is set to `inherited`, the project SDK is used. Otherwise the SDK for the corresponding value of java version is used for this module.

    For example see docs for `IdeaModule`

    Since:
      1.0

  - ### setJdkName

    public void setJdkName(String jdkName)
    Sets the jdk name.
    Since:
      1.0

  - ### getLanguageLevel

    public IdeaLanguageLevel getLanguageLevel()
    The module specific language Level to use for this module. When `null`, the module will inherit the language level from the idea project.

    The Idea module language level is based on the `sourceCompatibility` settings for the associated Gradle project.

    Since:
      2.11

  - ### setLanguageLevel

    public void setLanguageLevel(IdeaLanguageLevel languageLevel)
    Sets the language level.
    Since:
      2.12

  - ### getTargetBytecodeVersion

    public JavaVersion getTargetBytecodeVersion()
    The module specific bytecode version to use for this module. When `null`, the module will inherit the bytecode version from the idea project.

    The Idea module bytecode version is based on the `targetCompatibility` settings for the associated Gradle project.

    Since:
      2.11

  - ### setTargetBytecodeVersion

    public void setTargetBytecodeVersion(JavaVersion targetBytecodeVersion)
    Sets the target bytecode version.
    Since:
      2.12

  - ### getIml

    @Deprecated public IdeaModuleIml getIml()
    Deprecated.
    Will be removed in Gradle 10.
    See `iml(Action)`
    Since:
      1.0

  - ### getProject

    public Project getProject()
    An owner of this IDEA module.

    If IdeaModule requires some information from gradle this field should not be used for this purpose. IdeaModule instances should be configured with all necessary information by the plugin or user.

    Since:
      1.0

  - ### getPathFactory

    @Deprecated public PathFactory getPathFactory()
    Deprecated.
    Will be removed in Gradle 10.
    Returns the path factory used to construct paths in the generated *.iml file.
    Since:
      1.0

  - ### setPathFactory

    @Deprecated public void setPathFactory(PathFactory pathFactory)
    Deprecated.
    Will be removed in Gradle 10.
    Sets the path factory used to construct paths in the generated *.iml file.
    Since:
      1.0

  - ### isOffline

    public boolean isOffline()
    If true then external artifacts (e.g. those found in repositories) will not be included in the resulting classpath (only project and local file dependencies will be included).
    Since:
      1.0

  - ### setOffline

    public void setOffline(boolean offline)
    Sets the offline.
    Since:
      1.0

  - ### getSingleEntryLibraries

    public Map<String, Iterable<File>> getSingleEntryLibraries()
    Returns the single entry libraries.
    Since:
      1.0

  - ### setSingleEntryLibraries

    public void setSingleEntryLibraries(Map<String, Iterable<File>> singleEntryLibraries)
    Sets the single entry libraries.
    Since:
      1.0

  - ### iml

    @Deprecated public void iml(@DelegatesTo(IdeaModuleIml.class) Closure closure)
    Deprecated.
    Will be removed in Gradle 10.
    Enables advanced configuration like tinkering with the output XML or affecting the way existing *.iml content is merged with gradle build information.

    For example see docs for `IdeaModule`.

    Since:
      1.0

  - ### iml

    @Deprecated public void iml(Action<? super IdeaModuleIml> action)
    Deprecated.
    Will be removed in Gradle 10.
    Enables advanced configuration like tinkering with the output XML or affecting the way existing *.iml content is merged with gradle build information.

    For example see docs for `IdeaModule`.

    Since:
      3.5

  - ### getOutputFile

    public File getOutputFile()
    Configures output *.iml file. It's optional because the task should configure it correctly for you (including making sure it is unique in the multi-module build). If you really need to change the output file name (or the module name) it is much easier to do it via the moduleName property!

    Please refer to documentation on moduleName property. In IntelliJ IDEA the module name is the same as the name of the *.iml file.

    Since:
      1.0

  - ### setOutputFile

    public void setOutputFile(File newOutputFile)
    Sets the output file.
    Since:
      1.0

  - ### resolveDependencies

    public Set<Dependency> resolveDependencies()
    Resolves and returns the module's dependencies.
    Returns:
      dependencies
    Since:
      1.0

  - ### mergeXmlModule

    @Deprecated public void mergeXmlModule(Module xmlModule)
    Deprecated.
    Will be removed in Gradle 10.
    Merges the existing *.iml content with the configuration from this model.
    Since:
      1.0