EclipseProject

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

请参阅 EclipseProject.file(org.gradle.api.Action)

linkedResources

要添加到此 Eclipse 项目的链接资源。

name

配置 Eclipse 项目名称。它是可选的,因为任务应该会为您正确配置它。默认情况下,它会尝试使用project.name或在其前面加上project.path的一部分,以确保在多模块构建范围内 moduleName 唯一。模块名称的“唯一性”对于正确导入 Eclipse 是必需的,并且任务将确保名称是唯一的。

natures

要添加到此 Eclipse 项目的 nature。

referencedProjects

此 Eclipse 项目的引用项目(*不是*:Java 构建路径项目引用)。

resourceFilters

Eclipse 项目的资源过滤器。

方法

方法描述
buildCommand(buildCommand)

向 Eclipse 项目添加构建命令。

buildCommand(args, buildCommand)

向 Eclipse 项目添加带参数的构建命令。

file(action)

启用高级配置,例如修改输出 XML 或影响现有 .project 内容与 Gradle 构建信息的合并方式。例如,请参阅 EclipseProject 的文档

linkedResource(args)

向 Eclipse 项目添加资源链接(也称“源链接”)。

natures(natures)

将 nature 条目附加到 Eclipse 项目。

referencedProjects(referencedProjects)

此 Eclipse 项目的引用项目(*不是*:Java 构建路径项目引用)。

resourceFilter(configureClosure)

向 Eclipse 项目添加资源过滤器。

resourceFilter(configureAction)

向 Eclipse 项目添加资源过滤器。

脚本块

描述
file

启用高级配置,例如修改输出 XML 或影响现有 .project 内容与 Gradle 构建信息的合并方式

属性详情

List<BuildCommand> buildCommands

要添加到此 Eclipse 项目的构建命令。

例如,请参阅 EclipseProject 的文档。

默认使用 eclipsejava 插件
Java 构建器,以及适当的 Scala 和 Web 构建器。

String comment

用于 Eclipse 项目的注释。默认情况下,它将配置为 project.description

例如,请参阅 EclipseProject 的文档。

默认使用 eclipsejava 插件
project.description

Set<Link> linkedResources

要添加到此 Eclipse 项目的链接资源。

例如,请参阅 EclipseProject 的文档。

默认使用 eclipsejava 插件
[]

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 的文档。

默认使用 eclipsejava 插件
${project.name}(有时会以 ${project.path} 的部分内容作为前缀以保证唯一性)

List<String> natures

要添加到此 Eclipse 项目的 nature。

例如,请参阅 EclipseProject 的文档。

默认使用 eclipsejava 插件
Java nature,以及适当的 Groovy、Scala 和 Web nature。

Set<String> referencedProjects

此 Eclipse 项目的引用项目(*不是*:Java 构建路径项目引用)。

引用项目并不意味着在它们之间添加构建路径依赖项!如果您需要配置构建路径依赖项,请使用 Gradle 的 dependencies 部分或 eclipse.classpath.whenMerged { classpath -> ... } 来操纵 classpath 条目

例如,请参阅 EclipseProject 的文档。

默认使用 eclipsejava 插件
[]

Set<ResourceFilter> resourceFilters (read-only)

Eclipse 项目的资源过滤器。

默认使用 eclipsejava 插件
[]

方法详情

void buildCommand(String buildCommand)

向 Eclipse 项目添加构建命令。

例如,请参阅 EclipseProject 的文档。

void buildCommand(Map<String, String> args, String buildCommand)

向 Eclipse 项目添加带参数的构建命令。

例如,请参阅 EclipseProject 的文档。

void file(Action<? super XmlFileContentMerger> action)

启用高级配置,例如修改输出 XML 或影响现有 .project 内容与 Gradle 构建信息的合并方式。例如,请参阅 EclipseProject 的文档

void linkedResource(Map<String, String> args)

向 Eclipse 项目添加资源链接(也称“源链接”)。

例如,请参阅 EclipseProject 的文档。

void natures(String... natures)

将 nature 条目附加到 Eclipse 项目。

例如,请参阅 EclipseProject 的文档。

void referencedProjects(String... referencedProjects)

此 Eclipse 项目的引用项目(*不是*:Java 构建路径项目引用)。

引用项目并不意味着在它们之间添加构建路径依赖项!如果您需要配置构建路径依赖项,请使用 Gradle 的 dependencies 部分或 eclipse.classpath.whenMerged { classpath -> ... } 来操纵 classpath 条目

ResourceFilter resourceFilter(Closure configureClosure)

向 Eclipse 项目添加资源过滤器。

有关示例,请参阅 ResourceFilter 的文档。

ResourceFilter resourceFilter(Action<? super ResourceFilter> configureAction)

向 Eclipse 项目添加资源过滤器。

有关示例,请参阅 ResourceFilter 的文档。

脚本块详情

file { }

启用高级配置,例如修改输出 XML 或影响现有 .project 内容与 Gradle 构建信息的合并方式

传递给 whenMerged{} 和 beforeMerged{} 闭包的对象类型是 Project

例如,请参阅 EclipseProject 的文档。

委托给
来自 fileXmlFileContentMerger