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 專案的性質 (natures)。

referencedProjects

這個 Eclipse 專案的參考專案 (*不是*: java 建置路徑專案參考)。

resourceFilters

eclipse 專案的資源過濾器。

方法

方法描述
buildCommand(buildCommand)

將建置命令加入到 eclipse 專案。

buildCommand(args, buildCommand)

將帶有引數的建置命令加入到 eclipse 專案。

file(action)

啟用進階設定,例如調整輸出 XML 或影響現有的 .project 內容與 gradle 建置資訊合併的方式。例如,請參閱 EclipseProject 的文件

linkedResource(args)

將資源連結(又稱「來源連結」)加入到 eclipse 專案。

natures(natures)

將性質 (natures) 條目附加到 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 版本起提供 since

如果您的專案在名稱獨一無二方面遇到問題,建議您始終從根目錄執行 gradle eclipse,例如針對所有子專案,包括產生 .classpath。如果您僅針對單個子專案執行 eclipse 專案的產生,則可能會得到不同的結果,因為唯一名稱是根據特定建置執行中涉及的 eclipse 專案計算的。

如果您更新專案名稱,請確保您從根目錄執行 gradle eclipse,例如針對所有子專案。原因是可能存在依賴於已修改 eclipse 專案名稱的子專案。因此,您也希望它們被產生,因為 .classpath 中的專案相依性需要參考已修改的專案名稱。基本上,對於非簡單專案,建議始終從根目錄執行 gradle eclipse。

例如,請參閱 EclipseProject 的文件

預設使用 eclipsejava 外掛程式
${project.name} (有時在前面加上 ${project.path} 的部分以保證唯一性)

List<String> natures

要加入到這個 Eclipse 專案的性質 (natures)。

例如,請參閱 EclipseProject 的文件

預設使用 eclipsejava 外掛程式
Java 性質 (nature),加上 Groovy、Scala 和 Web 性質 (natures) (如果適用)。

Set<String> referencedProjects

這個 Eclipse 專案的參考專案 (*不是*: java 建置路徑專案參考)。

參考專案並不代表在它們之間加入建置路徑相依性!如果您需要設定建置路徑相依性,請使用 Gradle 的 dependencies 區段或 eclipse.classpath.whenMerged { classpath -> ... 來操作類別路徑條目

例如,請參閱 EclipseProject 的文件

預設使用 eclipsejava 外掛程式
[]

Set<ResourceFilter> resourceFilters (唯讀)

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)

將性質 (natures) 條目附加到 eclipse 專案。

例如,請參閱 EclipseProject 的文件

void referencedProjects(String... referencedProjects)

這個 Eclipse 專案的參考專案 (*不是*: java 建置路徑專案參考)。

參考專案並不代表在它們之間加入建置路徑相依性!如果您需要設定建置路徑相依性,請使用 Gradle 的 dependencies 區段或 eclipse.classpath.whenMerged { classpath -> ... 來操作類別路徑條目

ResourceFilter resourceFilter(Closure configureClosure)

將資源過濾器加入到 eclipse 專案。

例如,請參閱 ResourceFilter 的文件

ResourceFilter resourceFilter(Action<? super ResourceFilter> configureAction)

將資源過濾器加入到 eclipse 專案。

例如,請參閱 ResourceFilter 的文件

腳本區塊詳細資訊

file { }

啟用進階設定,例如調整輸出 XML 或影響現有的 .project 內容與 gradle 建置資訊合併的方式

傳遞給 whenMerged{} 和 beforeMerged{} 閉包的物件類型為 Project

例如,請參閱 EclipseProject 的文件

委派給
XmlFileContentMerger,來自 file