Groovy Documentation

org.gradle.plugins.ide.idea.model
[Groovy] Class IdeaModule

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

class IdeaModule
extends java.lang.Object

Model for idea module.

Example of use with a blend of all possible properties. Bear in mind that usually you don't have configure idea module directly because Gradle configures it for free!

 apply plugin: 'java'
 apply plugin: 'idea'

 //for the sake of the example lets have a 'provided' dependency configuration
 configurations {
   provided
   provided.extendsFrom(compile)
 }

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

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

     //and some extra test source dirs
     testSourceDirs += file('some-extra-test-dir')

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

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

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

     //if you prefer different java version than inherited from IDEA project
     javaVersion = '1.6'

     //if you need to put provided dependencies on the classpath
     scopes.COMPILE.plus += configurations.provided

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

     //if you love browsing javadocs
     downloadJavadoc = true

     //and hate reading sources :)
     downloadSources = false

     //if you want parts of paths in resulting *.iml to be replaced by variables (files)
     variables = [GRADLE_HOME: file('~/cool-software/gradle')]
     //pathVariables
     //TODO SF: think about moving the pathVariables to the upper level

     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!!!')
       }

       //beforeMerged and whenMerged closures are the highest voodoo
       //and probably should be used only to solve tricky edge cases:

       //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 ->
         //If you really want to update the javaVersion
         module.javaVersion = '1.6'
         //but you don't want to do it here...
         //because you can do it much easier in idea.module configuration!
       }
     }
   }
 }

 
Author: Szczepan Faber, created at: 3/31/11


Property Summary
boolean downloadJavadoc

Whether to download and add javadoc associated with the dependency jars.

boolean downloadSources

Whether to download and add sources associated with the dependency jars.

java.util.Set excludeDirs

The directories to be excluded.

IdeaModuleIml iml

java.lang.Boolean inheritOutputDirs

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 outputDir and testOutputDir.

java.lang.String javaVersion

The JDK to use for this module.

java.io.File moduleDir

The content root directory of the module.

java.lang.String name

Idea module name; controls the name of the *.iml file

For example see docs for IdeaModule

java.io.File outputDir

The output directory for production classes.

PathFactory pathFactory

java.lang.Object project

java.util.Map scopes

The keys of this map are the Intellij scopes.

java.util.Set sourceDirs

The directories containing the production sources.

java.io.File testOutputDir

The output directory for test classes.

java.util.Set testSourceDirs

The directories containing the test sources.

java.util.Map variables

The variables to be used for replacing absolute paths in the iml entries.

Module xmlModule

 
Method Summary
protected void generate()

protected Path getContentPath()

protected java.util.Set getDependencies()

protected java.util.Set getExcludePaths()

protected java.io.File getOutputFile()

protected Path getOutputPath()

protected java.util.Set getSourcePaths()

protected Path getTestOutputPath()

protected java.util.Set getTestSourcePaths()

void iml(groovy.lang.Closure closure)

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

protected void mergeXmlModule(Module xmlModule)

protected java.lang.Object path(java.io.File dir)

protected void setOutputFile(java.io.File newOutputFile)

 
Methods inherited from class java.lang.Object
java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString()
 

Property Detail

downloadJavadoc

boolean downloadJavadoc
Whether to download and add javadoc associated with the dependency jars.

For example see docs for IdeaModule


downloadSources

boolean downloadSources
Whether to download and add sources associated with the dependency jars.

For example see docs for IdeaModule


excludeDirs

java.util.Set excludeDirs
The directories to be excluded.

For example see docs for IdeaModule


iml

IdeaModuleIml iml


inheritOutputDirs

java.lang.Boolean inheritOutputDirs
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 outputDir and testOutputDir.

For example see docs for IdeaModule


javaVersion

java.lang.String javaVersion
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


moduleDir

java.io.File moduleDir
The content root directory of the module.

For example see docs for IdeaModule


name

java.lang.String name
Idea module name; controls the name of the *.iml file

For example see docs for IdeaModule


outputDir

java.io.File outputDir
The output directory for production classes. If null, no entry will be created.

For example see docs for IdeaModule


pathFactory

PathFactory pathFactory


project

java.lang.Object project


scopes

java.util.Map scopes
The keys of this map are the Intellij scopes. Each key points to another map that has two keys, plus and minus. The values of those keys are sets 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 'provided' dependencies in the output *.iml file:

 apply plugin: 'java'
 apply plugin: 'idea'

 configurations {
   provided
   provided.extendsFrom(compile)
 }

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

 idea {
   module {
     scopes.COMPILE.plus += configurations.provided
   }
 }
 


sourceDirs

java.util.Set sourceDirs
The directories containing the production sources.

For example see docs for IdeaModule


testOutputDir

java.io.File testOutputDir
The output directory for test classes. If null, no entry will be created.

For example see docs for IdeaModule


testSourceDirs

java.util.Set testSourceDirs
The directories containing the test sources.

For example see docs for IdeaModule


variables

java.util.Map variables
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


xmlModule

Module xmlModule


 
Method Detail

generate

protected void generate()


getContentPath

protected Path getContentPath()


getDependencies

protected java.util.Set getDependencies()


getExcludePaths

protected java.util.Set getExcludePaths()


getOutputFile

protected java.io.File getOutputFile()


getOutputPath

protected Path getOutputPath()


getSourcePaths

protected java.util.Set getSourcePaths()


getTestOutputPath

protected Path getTestOutputPath()


getTestSourcePaths

protected java.util.Set getTestSourcePaths()


iml

void iml(groovy.lang.Closure closure)
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


mergeXmlModule

protected void mergeXmlModule(Module xmlModule)


path

protected java.lang.Object path(java.io.File dir)


setOutputFile

protected void setOutputFile(java.io.File newOutputFile)


 

Groovy Documentation