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

Constructors

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

Properties

Link copied to clipboard
open var contentRoot: File
Link copied to clipboard
open var excludeDirs: Set<File>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open var jdkName: String
Link copied to clipboard
open var name: String
Link copied to clipboard
open var outputDir: File
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open var resourceDirs: Set<File>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open var sourceDirs: Set<File>
Link copied to clipboard
Link copied to clipboard
This field is @Deprecated, please use testResources instead.
Link copied to clipboard
Link copied to clipboard
This field is @Deprecated, please use testSources instead.
Link copied to clipboard

Functions

Link copied to clipboard
The module specific language Level to use for this module.
Link copied to clipboard
open fun getOutputFile(): File
Configures output *.iml file.
Link copied to clipboard
The module specific bytecode version to use for this module.
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.
Link copied to clipboard
Whether to download and add javadoc associated with the dependency jars.
Link copied to clipboard
Whether to download and add sources associated with the dependency jars.
Link copied to clipboard
open fun isOffline(): Boolean
If true then external artifacts (e.g.
Link copied to clipboard
open fun mergeXmlModule(xmlModule: Module)
Link copied to clipboard
Resolves and returns the module's dependencies.
Link copied to clipboard
open fun setDownloadJavadoc(downloadJavadoc: Boolean)
Link copied to clipboard
open fun setDownloadSources(downloadSources: Boolean)
Link copied to clipboard
open fun setLanguageLevel(languageLevel: IdeaLanguageLevel)
Link copied to clipboard
open fun setOffline(offline: Boolean)
Link copied to clipboard
open fun setOutputFile(newOutputFile: File)
Link copied to clipboard
open fun setTargetBytecodeVersion(targetBytecodeVersion: JavaVersion)