# IdeaModule

abstract class IdeaModule(source)

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
      }
    }

Content copied to clipboard
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
          }
        }
      }
    }

Content copied to clipboard

## Constructors

IdeaModule
Link copied to clipboard
@Inject
constructor(project: Project, iml: IdeaModuleIml)

## Properties

contentRoot
Link copied to clipboard
open var contentRoot: File
excludeDirs
Link copied to clipboard
open var excludeDirs: Set<File>
generatedSourceDirs
Link copied to clipboard
open var generatedSourceDirs: Set<File>
iml
Link copied to clipboard
val iml: IdeaModuleIml
inheritOutputDirs
Link copied to clipboard
open var inheritOutputDirs: Boolean
jdkName
Link copied to clipboard
open var jdkName: String
name
Link copied to clipboard
open var name: String
outputDir
Link copied to clipboard
open var outputDir: File
pathFactory
Link copied to clipboard
open var pathFactory: PathFactory
pathVariables
Link copied to clipboard
open var pathVariables: Map<String, File>
project
Link copied to clipboard
val project: Project
resourceDirs
Link copied to clipboard
open var resourceDirs: Set<File>
scopes
Link copied to clipboard
open var scopes: Map<String, Map<String, Collection<Configuration>>>
singleEntryLibraries
Link copied to clipboard
open var singleEntryLibraries: Map<String, Iterable<File>>
sourceDirs
Link copied to clipboard
open var sourceDirs: Set<File>
testOutputDir
Link copied to clipboard
open var testOutputDir: File

## Functions

getLanguageLevel
Link copied to clipboard
open fun getLanguageLevel(): IdeaLanguageLevel
The module specific language Level to use for this module.
getOutputFile
Link copied to clipboard
open fun getOutputFile(): File
Configures output *.iml file.
getTargetBytecodeVersion
Link copied to clipboard
open fun getTargetBytecodeVersion(): JavaVersion
The module specific bytecode version to use for this module.
getTestResources
Link copied to clipboard
abstract fun getTestResources(): ConfigurableFileCollection
The complete and up-to-date collection of test resource directories.
getTestSources
Link copied to clipboard
abstract fun getTestSources(): ConfigurableFileCollection
The complete and up-to-date collection of test source directories
iml
Link copied to clipboard
open fun iml(@DelegatesTo(value = IdeaModuleIml::class) closure: Closure)
open fun iml(action: Action<in IdeaModuleIml>)
Enables advanced configuration like tinkering with the output XML or affecting the way existing *.iml content is merged with gradle build information.
isDownloadJavadoc
Link copied to clipboard
open fun isDownloadJavadoc(): Boolean
Whether to download and add javadoc associated with the dependency jars.
isDownloadSources
Link copied to clipboard
open fun isDownloadSources(): Boolean
Whether to download and add sources associated with the dependency jars.
isOffline
Link copied to clipboard
open fun isOffline(): Boolean
If true then external artifacts (e.g.
mergeXmlModule
Link copied to clipboard
open fun mergeXmlModule(xmlModule: Module)
Merges the existing *.iml content with the configuration from this model.
resolveDependencies
Link copied to clipboard
open fun resolveDependencies(): Set<Dependency>
Resolves and returns the module's dependencies.
setDownloadJavadoc
Link copied to clipboard
open fun setDownloadJavadoc(downloadJavadoc: Boolean)
setDownloadSources
Link copied to clipboard
open fun setDownloadSources(downloadSources: Boolean)
setLanguageLevel
Link copied to clipboard
open fun setLanguageLevel(languageLevel: IdeaLanguageLevel)
setOffline
Link copied to clipboard
open fun setOffline(offline: Boolean)
setOutputFile
Link copied to clipboard
open fun setOutputFile(newOutputFile: File)
setTargetBytecodeVersion
Link copied to clipboard
open fun setTargetBytecodeVersion(targetBytecodeVersion: JavaVersion)