如果您想将 Buildship 与 Eclipse 一起使用,那么您就不走运了,因为 gradle 目前不支持此功能(请参阅https://discuss.gradle.org/t/add-sources-manually-for-a-dependency-which-缺乏他们/11456/8)。
如果您可以不使用 Buildship 并手动生成 Eclipse 点文件,您可以在 build.gradle 中执行以下操作:
apply plugin: 'eclipse'
eclipse.classpath.file {
withXml {
xml ->
def node = xml.asNode()
node.classpathentry.forEach {
if(it.@kind == 'lib') {
def sourcePath = it.@path.replace('.jar', '-sources.jar')
if(file(sourcePath).exists()) {
it.@sourcepath = sourcePath
}
}
}
}
}
然后,您将从命令行运行gradle eclipse
并使用 Import -> "Existing Projects into Workspace" 将项目导入 Eclipse
另一个(可能更好)的选择是使用这样的平面文件存储库:
repositories {
flatDir {
dirs 'lib'
}
见https://docs.gradle.org/current/userguide/dependency_management.html#sec:flat_dir_resolver
然后,您将像其他任何依赖项一样包含您的依赖项;在你的情况下:
compile ':local-lib'
这样,Buildship 将自动查找-sources.jar
文件,因为flatDir
大部分情况下它就像一个常规存储库。