| API 文档 | 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 Jar 并将其与依赖 Jar 关联。默认为 false。 |
downloadSources | 是否下载源代码 Jar 并将其与依赖 Jar 关联。默认为 true。 |
file | |
minusConfigurations | 要从类路径条目中排除的配置。 |
plusConfigurations | 要作为类路径条目添加的配置。 |
| 方法 | 描述 |
containers(containers) | 要添加的更多类路径容器。 |
file(action) | 启用高级配置,例如调整输出 XML 或影响现有 .classpath 文件内容与 Gradle 构建信息合并的方式。传递给 whenMerged{} 和 beforeMerged{} 闭包的对象类型为 |
File defaultOutputDir
Eclipse 放置编译后的类的默认输出目录。
请参阅 EclipseClasspath 获取示例。
- 默认使用
eclipse和java插件 ${project.projectDir}/bin/default
Collection<Configuration> minusConfigurations
Collection<Configuration>要从类路径条目中排除的配置。
请参阅 EclipseClasspath 获取示例。
- 默认使用
eclipse和java插件 []
Collection<Configuration> plusConfigurations
Collection<Configuration>要作为类路径条目添加的配置。
请参阅 EclipseClasspath 获取示例。
- 默认使用
eclipse和java插件 project.configurations.testRuntime
void file(Action<? super XmlFileContentMerger> action)
Action<? super XmlFileContentMerger>启用高级配置,例如调整输出 XML 或影响现有 .classpath 文件内容与 Gradle 构建信息合并的方式。传递给 whenMerged{} 和 beforeMerged{} 闭包的对象类型为 Classpath。
请参阅 EclipseProject 获取示例。
启用高级配置,例如调整输出 XML 或影响现有 .classpath 文件内容与 Gradle 构建信息合并的方式。传递给 whenMerged{} 和 beforeMerged{} 闭包的对象类型为 Classpath。
请参阅 EclipseProject 获取示例。
- 委托给
XmlFileContentMerger来自file