将模块导出到Eclipse .ClassPath文件
我有一个较旧的项目,该项目需要在Eclipse的 .classPath
文件中具有模块导出,以便它可以从该模块中解析一些类。如果我通过Eclipse的Build Path Editor生成类似的classPath条目:
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/">
<attributes>
<attribute name="module" value="true"/>
<attribute name="add-exports" value="java.desktop/com.sun.java.swing.plaf.motif=ALL-UNNAMED"/>
</attributes>
</classpathentry>
自然,我想拥有Gradle生成的条目,我终于设法做到了:
eclipse.classpath.file {
whenMerged { // remove any JRE containers
entries.findAll{ it.path ==~ '.*JRE_CONTAINER.*' }.each { entries.remove(it) }
}
withXml { // add one with the required export
def node = it.asNode()
def cpe = new Node(node, 'classpathentry', [kind: 'con', path: 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11/'])
def attrs = new Node(cpe, 'attributes')
new Node(attrs, 'attribute', [name: 'module', value: 'true'])
new Node(attrs, 'attribute', [name: 'add-exports', value: 'java.desktop/com.sun.java.swing.plaf.motif=ALL-UNNAMED'])
}
}
但是这似乎是粗俗而冗长的。是否有一种更简单的方法可以做这样的事情?
更新:另外,这仅在运行 gradle eclipse
时起作用,但在使用BuildShip进行“刷新Gradle Project”时不行 - AS whermerged 中创建一个容器,然后添加属性,而我无法做到。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案,属性节点可以通过
entryAttributes
AbstractClassEntry 类的字段。这样,我就可以做......
并且它也将被Buildship应用。
I've found the solution, the attribute(s) nodes are accessible via the
entryAttributes
field of the AbstractClassEntry class.This way, I can just do...
...and it will be applied by Buildship, too.