| API文档: | IdeaModule |
|---|
启用 IDEA 插件的微调模块详细信息(*.iml 文件)。
混合使用大多数可能属性的示例。通常,您不必直接配置此模型,因为 Gradle 会为您配置它。
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
}
}
为了解决边缘情况,用户可以对生成的 XML 文件执行高级配置。还可以通过 beforeMerged 和 whenMerged 闭包影响 IDEA 插件合并现有配置的方式。
beforeMerged 和whenMerged 闭包接收一个Module参数
高级配置示例:
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
}
}
}
}
| 财产 | 描述 |
contentRoot | 模块的内容根目录。 |
downloadJavadoc | 是否下载并添加与依赖 jar 关联的 javadoc。默认为 false。 |
downloadSources | 是否下载并添加与依赖项 jar 关联的源。默认为 true。 |
excludeDirs | 要排除的目录。 |
generatedSourceDirs | 包含生成的源(生产源和测试源)的目录。 |
iml | |
inheritOutputDirs | 如果为 true,则该模块的输出目录将位于项目的输出目录下方;否则,它们将被设置为 |
jdkName | 用于此模块的 JDK。如果 |
languageLevel | 用于该模块的模块特定语言级别。当 时 |
name | 配置模块名称,即*.iml文件的名称。 |
outputDir | 生产类的输出目录。如果 |
outputFile | 配置输出 *.iml 文件。它是可选的,因为任务应该为您正确配置它(包括确保它在多模块构建中是唯一的)。如果您确实需要更改输出文件名(或模块名称),那么通过moduleName属性来完成会更容易! |
resourceDirs | 包含资源的目录。 |
scopes | 该映射的关键是 IDEA 范围。每个键都指向另一个映射,该映射有两个键:加号和减号。这些键的值是 |
sourceDirs | 包含生产源的目录。例如,请参阅文档 |
targetBytecodeVersion | 用于该模块的模块特定字节码版本。当 时 |
testOutputDir | 测试类的输出目录。如果 |
testResourceDirs | 已弃用 包含测试资源的目录。 |
testResources | 完整且最新的测试资源目录集合。这应该是首选, |
testSourceDirs | 已弃用 包含测试源的目录。
请注意,对默认测试目录的最新更改可能不会反映在此集合中,因此 |
testSources | 完整且最新的测试源目录集合这应该是首选, |
| 方法 | 描述 |
iml(action) | 启用高级配置,例如修改输出 XML 或影响现有 *.iml 内容与 gradle 构建信息合并的方式。 |
| 堵塞 | 描述 |
iml | 启用高级配置,例如修改输出 XML 或影响现有 *.iml 内容与 gradle 构建信息合并的方式。 |
Boolean inheritOutputDirs
如果为 true,则该模块的输出目录将位于项目的输出目录下方;否则,它们将被设置为IdeaModule.getOutputDir()和指定的目录IdeaModule.getTestOutputDir()。
例如,请参阅文档IdeaModule
- 默认使用
idea插件: null- 默认使用
idea和java插件: null
String jdkName
用于此模块的 JDK。如果null,则使用现有或默认 ipr XML(继承)的值。如果设置为inherited,则使用项目SDK。否则,该模块将使用对应java版本值的SDK。
例如,请参阅文档IdeaModule
- 默认使用
idea插件: 'inherited'
IdeaLanguageLevel languageLevel
用于该模块的模块特定语言级别。当 时null,模块将从 idea 项目继承语言级别。
Idea 模块语言级别基于sourceCompatibility关联 Gradle 项目的设置。
- 默认使用
idea和java插件: project.sourceCompatibility
String name
配置模块名称,即*.iml文件的名称。
它是可选的,因为任务应该为您正确配置它。默认情况下,它将尝试使用project.name或在其前面加上project.path的一部分作为前缀,以确保模块名称在多模块构建的范围内是唯一的。模块名称的“唯一性”对于正确导入 IDEA 是必需的,并且任务将确保名称是唯一的。
自1.0-milestone-2
如果您的项目存在唯一名称问题,建议始终gradle idea从根运行,即对于所有子项目。如果您仅针对单个子项目运行 IDEA 模块的生成,则可能会得到不同的结果,因为唯一名称是根据特定构建运行中涉及的 IDEA 模块计算的。
如果更新模块名称,请确保gradle idea从根运行,例如对于所有子项目,包括 IDEA 项目的生成。原因是可能有子项目依赖于修改了模块名称的子项目。因此您也希望生成它们,因为模块依赖项需要引用修改后的项目名称。基本上,对于重要的项目,建议始终gradle idea从根运行。
例如,请参阅文档IdeaModule
- 默认使用
idea插件: ${project.name}(sometimes prefixed with parts of${project.path}to guarantee uniqueness)
File outputFile
配置输出 *.iml 文件。它是可选的,因为任务应该为您正确配置它(包括确保它在多模块构建中是唯一的)。如果您确实需要更改输出文件名(或模块名称),那么通过moduleName属性来完成会更容易!
请参阅有关moduleName属性的文档。在 IntelliJ IDEA 中,模块名称与 *.iml 文件的名称相同。
- 默认使用
idea插件: - #姓名+
'.iml'
Map<String, Map<String, Collection<Configuration>>> scopes
Map<String, Map<String, Collection<Configuration>>>该映射的关键是 IDEA 范围。每个键都指向另一个映射,该映射有两个键:加号和减号。这些键的值是Configuration对象的集合。添加正配置的文件减go负配置的文件。请参阅下面的示例...
如何使用scopes属性在输出*.iml文件中启用“performanceTestCompile”依赖项的示例:
plugins {
id 'java'
id 'idea'
}
configurations {
performanceTestCompile
performanceTestCompile.extendsFrom(testCompile)
}
dependencies {
//performanceTestCompile "some.interesting:dependency:1.0"
}
idea {
module {
scopes.TEST.plus += [ configurations.performanceTestCompile ]
}
}
- 默认使用
idea插件: [:]- 默认使用
idea和java插件: -
COMPILE->project.configurations.compileClasspathRUNTIME->project.configurations.runtimeClasspath - project.configurations.compileClasspathTEST->project.configurations.testRuntimeClasspath - project.configurations.runtimeClasspathPROVIDED
包含生产源的目录。例如,请参阅文档IdeaModule
- 默认使用
idea插件: []- 默认使用
idea和java插件: - 项目.sourceSets.main.allJava
JavaVersion targetBytecodeVersion
用于该模块的模块特定字节码版本。当 时null,模块将从 idea 项目继承字节码版本。
Idea 模块字节码版本基于targetCompatibility关联 Gradle 项目的设置。
- 默认使用
idea和java插件: project.targetCompatibility
注意:此属性已弃用,并将在 Gradle 的下一个主要版本中删除。
包含测试资源的目录。
例如,请参阅此字段的文档,请改用。IdeaModule
@DeprecatedIdeaModule.getTestResources()
- 默认使用
idea插件: []- 默认使用
idea和java插件: - 资源目录来自
project.sourceSets.test.resources
ConfigurableFileCollection testResources(只读)
完整且最新的测试资源目录集合。这应该是首选,IdeaModule.getTestResourceDirs()因为它将包括对默认目录的最新更改。
- 默认使用
idea插件: []- 默认使用
idea和java插件: - 基于可用测试套件中的资源
注意:此属性已弃用,并将在 Gradle 的下一个主要版本中删除。
包含测试源的目录。
请注意,对默认测试目录的最新更改可能不会反映在此集合中,因此IdeaModule.getTestSources()应优先考虑。
例如,请参阅此字段的文档,请改用。IdeaModule
@DeprecatedIdeaModule.getTestSources()
- 默认使用
idea插件: []- 默认使用
idea和java插件: - 项目.sourceSets.test.allJava
ConfigurableFileCollection testSources(只读)
完整且最新的测试源目录集合这应该是首选,IdeaModule.getTestSourceDirs()因为它将包括对默认目录的最新更改。
- 默认使用
idea插件: []- 默认使用
idea和java插件: - 基于可用测试套件中的源目录
void iml(行动)Action<? super IdeaModuleIml>
Action<? super IdeaModuleIml>启用高级配置,例如修改输出 XML 或影响现有 *.iml 内容与 gradle 构建信息合并的方式。
例如,请参阅 的文档IdeaModule。