Tom*_*han 7 gradle gradle-eclipse
我有一个gradle构建脚本,其中包含一些源集,这些源集都定义了各种依赖项(一些常见,一些没有),我正在尝试使用Eclipse插件让Gradle 为Eclipse 生成.project和.classpath文件,但我不能弄清楚如何获取所有依赖项.classpath; 由于某种原因,实际上添加了很少的外部依赖项.classpath,因此Eclipse构建失败并出现1400错误(使用gradle构建工作正常).
我已经定义了我的源集:
sourceSets {
setOne
setTwo {
compileClasspath += setOne.runtimeClasspath
}
test {
compileClasspath += setOne.runtimeClasspath
compileClasspath += setTwo.runtimeClasspath
}
}
dependencies {
setOne 'external:dependency:1.0'
setTwo 'other:dependency:2.0'
}
Run Code Online (Sandbox Code Playgroud)
由于我没有使用main源集,我认为这可能与它有关,所以我补充说
sourceSets.each { ss ->
sourceSets.main {
compileClasspath += ss.runtimeClasspath
}
}
Run Code Online (Sandbox Code Playgroud)
但这没有帮助.
我无法弄清楚所包含的库的任何常见属性,或者那些没有的库的常见属性,但我找不到任何我确定的东西(虽然当然必须有一些东西).我有一种感觉,所有包含的库都是test源集的依赖关系,无论是直接还是间接,但我还没有能够验证是否存在所有test的依赖关系.
如何确保放入所有源集的依赖项.classpath?
这个问题的解决方式与我昨天提出的类似问题密切相关:
// Create a list of all the configuration names for my source sets
def ssConfigNames = sourceSets.findAll { ss -> ss.name != "main" }.collect { ss -> "${ss.name}Compile".toString() }
// Find configurations matching those of my source sets
configurations.findAll { conf -> "${conf.name}".toString() in ssConfigNames }.each { conf ->
// Add matching configurations to Eclipse classpath
eclipse.classpath {
plusConfigurations += conf
}
}
Run Code Online (Sandbox Code Playgroud)
更新:
我也在Gradle 论坛中问了同样的问题,并得到了更好的解决方案:
eclipseClasspath.plusConfigurations = configurations.findAll { it.name.endsWith("Runtime") }
Run Code Online (Sandbox Code Playgroud)
它并不那么精确,因为它除了我的源集中的内容之外还添加了其他内容,但它保证它会起作用。而且眼睛更舒服=)
| 归档时间: |
|
| 查看次数: |
3520 次 |
| 最近记录: |