| 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的一部分作为前缀, 以确保moduleName在多模块构建的范围内是唯一的。正确导入 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) | 将 natures 条目附加到 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的一部分作为前缀, 以确保moduleName在多模块构建的范围内是唯一的。正确导入 Eclipse 需要模块名称的“唯一性”,并且任务将确保名称是唯一的。
确保项目名称唯一的逻辑自1.0-milestone-2 起可用
如果您的项目存在唯一名称问题,建议始终从根目录运行 gradle eclipse,例如对于所有子项目,包括 .classpath 的生成。如果您仅针对单个子项目运行 Eclipse 项目的生成,那么您可能会得到不同的结果,因为唯一名称是根据特定构建运行中涉及的 Eclipse 项目计算的。
如果您更新项目名称,请确保从根目录运行 gradle eclipse,例如对于所有子项目。原因是可能有子项目依赖于修改了eclipse项目名的子项目。因此您也希望生成它们,因为 .classpath 中的项目依赖项需要引用修改后的项目名称。基本上,对于重要的项目,建议始终从根目录运行 gradle eclipse。
例如,请参阅文档EclipseProject
- 默认带有
eclipse和java插件: ${project.name}(sometimes prefixed with parts of${project.path}to guarantee uniqueness)
此 Eclipse 项目引用的项目(*不是*:java 构建路径项目引用)。
引用项目并不意味着在它们之间添加构建路径依赖关系!如果需要配置构建路径依赖项,请使用 Gradle 的依赖项部分或 eclipse.classpath.whenMerged { classpath -> ... 来操作类路径条目
例如,请参阅文档EclipseProject
- 默认带有
eclipse和java插件: - []
void file(行动)Action<? super XmlFileContentMerger>
Action<? super XmlFileContentMerger>启用高级配置,例如修改输出 XML 或影响现有 .project 内容与 gradle 构建信息合并的方式。例如,请参阅文档EclipseProject
void referencedProjects(String...参考项目)
String...此 Eclipse 项目引用的项目(*不是*:java 构建路径项目引用)。
引用项目并不意味着在它们之间添加构建路径依赖关系!如果需要配置构建路径依赖项,请使用 Gradle 的依赖项部分或 eclipse.classpath.whenMerged { classpath -> ... 来操作类路径条目
ResourceFilter resourceFilter(配置动作)Action<? super ResourceFilter>
Action<? super ResourceFilter>向 eclipse 项目添加资源过滤器。
例如,请参阅文档ResourceFilter
启用高级配置,例如修改输出 XML 或影响现有 .project 内容与 gradle 构建信息合并的方式
传递给whenMerged{}和beforeMerged{}闭包的对象是类型Project
例如,请参阅文档EclipseProject