我使用的是Gradle eclipse插件,我正在尝试连接两个项目。其中一个项目是一个库,并且从来没有导出,因为我只是链接到实际项目中的库源。另一个项目应该有一个指向库源的虚拟链接,并将链接目录作为源目录添加到类路径中。我怎样才能用build.gradle做到这一点?具有添加所需项目(项目属性-> java Build Path ->项目)或虚拟源文件夹(项目属性-> Java Build Path -> Source -> Link Source...)的功能,但似乎不能将这些功能用于Gradle Java、Gradle eclipse或Gradle eclipse-wtp插件。
发布于 2015-07-10 02:48:59
我知道这是一个老帖子,但更详细地回答它可能会对将来像我一样的人有帮助,否则他们会花很多钱(浪费?)花时间用谷歌搜索得出答案。
我猜Peter在他的最后一条评论中暗示的是:
如果已声明了linkedResource,则可以使用classpath声明将其添加到.classpath文件中,如下所示:
eclipse {
project {
linkedResource name: 'java', type: '2', location: '[path-to-folder-to-be-linked]/src/main/java'
linkedResource name: 'java-resources', type: '2', location: '[path-to-folder-to-be-linked]/src/main/resources'
linkedResource name: 'test', type: '2', location: '[path-to-folder-to-be-linked]/src/test/java'
linkedResource name: 'test-resources', type: '2', location: '[path-to-folder-to-be-linked]/src/test/resources'
}
classpath {
file {
withXml {
def node = it.asNode()
node.appendNode('classpathentry', [kind: 'src', path: 'java', exported: true])
node.appendNode('classpathentry', [kind: 'src', path: 'java-resources', exported: true])
node.appendNode('classpathentry', [kind: 'src', path: 'test', exported: true])
node.appendNode('classpathentry', [kind: 'src', path: 'test-resources', exported: true])
}
}
}
}在我的例子中,我链接到网络上另一台机器上的文件,所以要链接的文件夹路径类似于"/Volumes/pf/Documents/workspace/...“。
在build.gradle中完成上述操作后,如果您正在使用STS/Eclipse中的Gradle工具,请打开Gradle task视图,选择项目,刷新任务列表,最后运行"eclipseClasspath“。
作者:我从这篇文章(Eclipse plugin: add new element to a classpathentry)中拼凑了上面的内容。
https://stackoverflow.com/questions/23524350
复制相似问题