EclipseClasspath

用於產生 Eclipse 專案的建置路徑設定。由 GenerateEclipseClasspath 任務用來產生 Eclipse .classpath 檔案。

以下範例示範各種組態選項。請記住,所有屬性都有合理的預設值;只有在預設值不符合您的需求時才明確設定它們。

plugins {
    id 'java'
    id 'eclipse'
}

configurations {
  provided
  someBoringConfig
}

eclipse {
  //if you want parts of paths in resulting file to be replaced by variables (files):
  pathVariables 'GRADLE_HOME': file('/best/software/gradle'), 'TOMCAT_HOME': file('../tomcat')

  classpath {
    //you can tweak the classpath of the Eclipse project by adding extra configurations:
    plusConfigurations += [ configurations.provided ]

    //you can also remove configurations from the classpath:
    minusConfigurations += [ configurations.someBoringConfig ]

    //if you want to append extra containers:
    containers 'someFriendlyContainer', 'andYetAnotherContainer'

    //customizing the classes output directory:
    defaultOutputDir = file('build-eclipse')

    //default settings for downloading sources and Javadoc:
    downloadSources = true
    downloadJavadoc = false

    //if you want to expose test classes to dependent projects
    containsTestFixtures = true

    //customizing which Eclipse source directories should be marked as test
    testSourceSets = [sourceSets.test]

    //customizing which dependencies should be marked as test on the project's classpath
    testConfigurations = [configurations.testCompileClasspath, configurations.testRuntimeClasspath]
  }
}

為了處理邊緣情況,使用者可以對產生的 XML 檔案執行進階組態。也可以透過 beforeMerged 和 whenMerged 閉包來影響 Eclipse 外掛程式合併現有組態的方式。

beforeMerged 和 whenMerged 閉包接收 Classpath 物件。

進階組態範例

plugins {
    id 'java'
    id 'eclipse'
}

eclipse {
  classpath {
    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 .classpath content is loaded from existing file
      //but before gradle build information is merged
      beforeMerged { classpath ->
        //you can tinker with the Classpath here
      }

      //closure executed after .classpath content is loaded from existing file
      //and after gradle build information is merged
      whenMerged { classpath ->
        //you can tinker with the Classpath here
      }
    }
  }
}

屬性

屬性描述
containers (容器)

要加入的類別路徑容器。

defaultOutputDir (預設輸出目錄)

Eclipse 放置編譯後類別的預設輸出目錄。

downloadJavadoc (下載 Javadoc)

是否下載 Javadoc Jar 並將其與依賴 Jar 關聯。預設值為 false。

downloadSources (下載原始碼)

是否下載原始碼 Jar 並將其與依賴 Jar 關聯。預設值為 true。

file (檔案)

請參閱 EclipseClasspath.file(org.gradle.api.Action)

minusConfigurations (排除的組態)

要從類別路徑條目中排除檔案的組態。

plusConfigurations (加入的組態)

要作為類別路徑條目加入檔案的組態。

方法

方法描述
containers(containers)

要加入的其他類別路徑容器。

file(action)

啟用進階組態,例如修改輸出 XML 或影響現有 .classpath 檔案的內容與 Gradle 建置資訊合併的方式。傳遞給 whenMerged{} 和 beforeMerged{} 閉包的物件類型為 Classpath

Script 區塊

區塊描述
file (檔案)

啟用進階組態,例如修改輸出 XML 或影響現有 .classpath 檔案的內容與 Gradle 建置資訊合併的方式。傳遞給 whenMerged{} 和 beforeMerged{} 閉包的物件類型為 Classpath

屬性詳細資訊

Set<String> containers

要加入的類別路徑容器。

請參閱 EclipseClasspath 以取得範例。

使用 eclipsejava 外掛程式的預設值
[JRE 容器]

File defaultOutputDir

Eclipse 放置編譯後類別的預設輸出目錄。

請參閱 EclipseClasspath 以取得範例。

使用 eclipsejava 外掛程式的預設值
${project.projectDir}/bin/default

boolean downloadJavadoc

是否下載 Javadoc Jar 並將其與依賴 Jar 關聯。預設值為 false。

請參閱 EclipseClasspath 以取得範例。

使用 eclipsejava 外掛程式的預設值
false (否)

boolean downloadSources

是否下載原始碼 Jar 並將其與依賴 Jar 關聯。預設值為 true。

請參閱 EclipseClasspath 以取得範例。

使用 eclipsejava 外掛程式的預設值
true (是)

Collection<Configuration> minusConfigurations

要從類別路徑條目中排除檔案的組態。

請參閱 EclipseClasspath 以取得範例。

使用 eclipsejava 外掛程式的預設值
[]

Collection<Configuration> plusConfigurations

要作為類別路徑條目加入檔案的組態。

請參閱 EclipseClasspath 以取得範例。

使用 eclipsejava 外掛程式的預設值
project.configurations.testRuntime (專案組態.測試執行時期)

方法詳細資訊

void containers(String... containers)

要加入的其他類別路徑容器。

請參閱 EclipseClasspath 以取得範例。

void file(Action<? super XmlFileContentMerger> action)

啟用進階組態,例如修改輸出 XML 或影響現有 .classpath 檔案的內容與 Gradle 建置資訊合併的方式。傳遞給 whenMerged{} 和 beforeMerged{} 閉包的物件類型為 Classpath

請參閱 EclipseProject 以取得範例。

Script 區塊詳細資訊

file { }

啟用進階組態,例如修改輸出 XML 或影響現有 .classpath 檔案的內容與 Gradle 建置資訊合併的方式。傳遞給 whenMerged{} 和 beforeMerged{} 閉包的物件類型為 Classpath

請參閱 EclipseProject 以取得範例。