我有一个 gradle 构建脚本,其中包含一些源集,这些源集都定义了各种依赖项(有些是常见的,有些不是),并且我正在尝试使用 Eclipse 插件来让 Gradle 生成.project
and .classpath
文件的 Eclipse,但我不知道如何将所有依赖项条目放入.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'
}
由于我没有使用main
source-set,我认为这可能与它有关,所以我添加了
sourceSets.each { ss ->
sourceSets.main {
compileClasspath += ss.runtimeClasspath
}
}
但这没有帮助。
我无法找出包含的库或未包含的库的任何共同属性,但我找不到任何我确定的东西(尽管当然必须有一些东西)。我有一种感觉,所有包含的库都是依赖项test
源集,无论是直接还是间接,但我无法验证这一点,只是注意到所有test
的依赖关系就在那里。
我如何确保的依赖关系all源集放入.classpath
?
这个问题的解决方式与类似的问题 https://stackoverflow.com/questions/17028368我昨天问:
// 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
}
}
Update:
I also 在 Gradle 论坛中问了同样的问题 http://forums.gradle.org/gradle/topics/how_do_i_get_the_gradle_eclipse_plugin_to_work_with_multiple_source_sets_that_have_different_dependencies,并得到了更好的解决方案:
eclipseClasspath.plusConfigurations = configurations.findAll { it.name.endsWith("Runtime") }
它并不那么精确,因为它除了我的源集中的内容之外还添加了其他内容,但它保证它会起作用。而且眼睛更舒服=)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)