| API 文档 | EclipseProject |
|---|
允许微调 Eclipse 插件的项目详细信息(.project 文件)
所有可能属性混合使用的示例。请注意,通常您无需直接配置 Eclipse 项目,因为 Gradle 会免费为您配置!
plugins {
id 'java'
id 'eclipse'
}
eclipse {
project {
//if you don't like the name Gradle has chosen
name = 'someBetterName'
//if you want to specify the Eclipse project's comment
comment = 'Very interesting top secret project'
//if you want to append some extra referenced projects in a declarative fashion:
referencedProjects 'someProject', 'someOtherProject'
//if you want to assign referenced projects
referencedProjects = ['someProject'] as Set
//if you want to append some extra natures in a declarative fashion:
natures 'some.extra.eclipse.nature', 'some.another.interesting.nature'
//if you want to assign natures in a groovy fashion:
natures = ['some.extra.eclipse.nature', 'some.another.interesting.nature']
//if you want to append some extra build command:
buildCommand 'buildThisLovelyProject'
//if you want to append a build command with parameters:
buildCommand 'buildItWithTheArguments', argumentOne: "I'm first", argumentTwo: "I'm second"
//if you want to create an extra link in the eclipse project,
//by location uri:
linkedResource name: 'someLinkByLocationUri', type: 'someLinkType', locationUri: 'file://someUri'
//by location:
linkedResource name: 'someLinkByLocation', type: 'someLinkType', location: '/some/location'
//if you don't want any node_modules folder to appear in Eclipse, you can filter it out:
resourceFilter {
appliesTo = 'FOLDERS'
type = 'EXCLUDE_ALL'
matcher {
id = 'org.eclipse.ui.ide.multiFilter'
arguments = '1.0-name-matches-false-false-node_modules'
}
}
}
}
为了处理边缘情况,用户可以对生成的 XML 文件执行高级配置。也可以通过 beforeMerged 和 whenMerged 闭包来影响 Eclipse 插件合并现有配置的方式。
beforeMerged 和 whenMerged 闭包接收 Project 对象
高级配置示例
plugins {
id 'java'
id 'eclipse'
}
eclipse {
project {
file {
//if you want to mess with the resulting XML in whatever way you fancy
withXml {
def node = it.asNode()
node.appendNode('xml', 'is what I love')
}
//closure executed after .project content is loaded from existing file
//but before gradle build information is merged
beforeMerged { project ->
//if you want skip merging natures... (a very abstract example)
project.natures.clear()
}
//closure executed after .project content is loaded from existing file
//and after gradle build information is merged
whenMerged { project ->
//you can tinker with the Project here
}
}
}
}
| 属性 | 描述 |
buildCommands | 要添加到此 Eclipse 项目的构建命令。 |
comment | 用于 Eclipse 项目的注释。默认情况下,它将被配置为 project.description |
file | |
linkedResources | 要添加到此 Eclipse 项目的链接资源。 |
name | 配置 Eclipse 项目名称。它是可选的,因为任务应该为您正确配置它。默认情况下,它会尝试使用project.name,或者在其前面加上project.path的一部分,以确保模块名称在多模块构建范围内是唯一的。模块名称的“唯一性”是正确导入 Eclipse 所必需的,任务将确保名称是唯一的。 |
natures | 要添加到此 Eclipse 项目的性质。 |
referencedProjects | 此 Eclipse 项目的引用项目(*不是*:Java 构建路径项目引用)。 |
resourceFilters | Eclipse 项目的资源过滤器。 |
| 方法 | 描述 |
buildCommand(buildCommand) | 向 Eclipse 项目添加构建命令。 |
buildCommand(args, buildCommand) | 向 Eclipse 项目添加带参数的构建命令。 |
file(action) | 允许高级配置,例如修改输出 XML 或影响现有 .project 内容与 gradle 构建信息合并的方式。例如,请参阅 |
linkedResource(args) | 向 Eclipse 项目添加资源链接(也称为“源链接”)。 |
natures(natures) | 将 nature 条目追加到 eclipse 项目。 |
referencedProjects(referencedProjects) | 此 Eclipse 项目的引用项目(*不是*:Java 构建路径项目引用)。 |
resourceFilter(configureClosure) | 向 eclipse 项目添加资源过滤器。 |
resourceFilter(configureAction) | 向 eclipse 项目添加资源过滤器。 |
| 块 | 描述 |
file | 允许进行高级配置,例如修改输出 XML 或影响现有 .project 内容与 gradle 构建信息合并的方式 |
List<BuildCommand> buildCommands
List<BuildCommand>要添加到此 Eclipse 项目的构建命令。
例如,请参阅 EclipseProject 的文档
- 默认使用
eclipse和java插件 - Java 构建器,以及适当的 Scala 和 Web 构建器。
String comment
用于 Eclipse 项目的注释。默认情况下,它将被配置为 project.description
例如,请参阅 EclipseProject 的文档
- 默认使用
eclipse和java插件 project.description
String name
配置 Eclipse 项目名称。它是可选的,因为任务应该为您正确配置它。默认情况下,它会尝试使用project.name,或者在其前面加上project.path的一部分,以确保模块名称在多模块构建范围内是唯一的。模块名称的“唯一性”是正确导入 Eclipse 所必需的,任务将确保名称是唯一的。
确保项目名称唯一的逻辑自 1.0-milestone-2 起可用
如果您的项目在唯一名称方面存在问题,建议始终从根目录运行 `gradle eclipse`,例如,为所有子项目(包括 .classpath 的生成)运行。如果您只为单个子项目运行 eclipse 项目的生成,那么您可能会得到不同的结果,因为唯一名称是根据特定构建运行中涉及的 eclipse 项目计算的。
如果您更新项目名称,请确保从根目录运行 `gradle eclipse`,例如,为所有子项目。原因可能是有子项目依赖于修改后的 eclipse 项目名称的子项目。因此,您希望它们也被生成,因为 .classpath 中的项目依赖项需要引用修改后的项目名称。基本上,对于非简单项目,建议始终从根目录运行 `gradle eclipse`。
例如,请参阅 EclipseProject 的文档
- 默认使用
eclipse和java插件 ${project.name}(有时以${project.path}的部分作为前缀以保证唯一性)
要添加到此 Eclipse 项目的性质。
例如,请参阅 EclipseProject 的文档
- 默认使用
eclipse和java插件 - Java nature,以及适当的 Groovy、Scala 和 Web nature。
此 Eclipse 项目的引用项目(*不是*:Java 构建路径项目引用)。
引用项目不意味着在它们之间添加构建路径依赖!如果您需要配置构建路径依赖,请使用 Gradle 的依赖项部分或 `eclipse.classpath.whenMerged { classpath -> ...` 来操作类路径条目
例如,请参阅 EclipseProject 的文档
- 默认使用
eclipse和java插件 - []
向 Eclipse 项目添加带参数的构建命令。
例如,请参阅 EclipseProject 的文档
void file(Action<? super XmlFileContentMerger> action)
Action<? super XmlFileContentMerger>允许高级配置,例如修改输出 XML 或影响现有 .project 内容与 gradle 构建信息合并的方式。例如,请参阅 EclipseProject 的文档。
void referencedProjects(String... referencedProjects)
String...此 Eclipse 项目的引用项目(*不是*:Java 构建路径项目引用)。
引用项目不意味着在它们之间添加构建路径依赖!如果您需要配置构建路径依赖,请使用 Gradle 的依赖项部分或 `eclipse.classpath.whenMerged { classpath -> ...` 来操作类路径条目
ResourceFilter resourceFilter(Closure configureClosure)
向 eclipse 项目添加资源过滤器。
例如,请参阅 ResourceFilter 的文档
ResourceFilter resourceFilter(Action<? super ResourceFilter> configureAction)
Action<? super ResourceFilter>向 eclipse 项目添加资源过滤器。
例如,请参阅 ResourceFilter 的文档
允许进行高级配置,例如修改输出 XML 或影响现有 .project 内容与 gradle 构建信息合并的方式
传递给 whenMerged{} 和 beforeMerged{} 闭包的对象类型为 Project
例如,请参阅 EclipseProject 的文档
- 委托给
- 来自
XmlFileContentMerger的file