我有一个较旧的项目,它需要在Eclipse的.classpath文件中导出一个模块,这样它就可以从这个模块解析一些类。如果通过Eclipse的构建路径编辑器生成类路径条目,则类路径条目如下所示:
<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 - as that doesn't consider withXml执行“刷新级项目”时才有效。因此,我需要在whenMerged中创建一个容器,并向它添加属性,这是我无法做到的。
发布于 2022-04-05 10:04:34
我找到了解决方案,属性节点可以通过entryAttributes field of the AbstractClassEntry class访问。
这样,我就可以.
eclipse.classpath.file {
whenMerged {
entries.find{ it.path ==~ '.*JRE_CONTAINER.*' }.each {
it.entryAttributes['module'] = true
it.entryAttributes['add-exports'] = 'java.desktop/com.sun.java.swing.plaf.motif=ALL-UNNAMED'
}
}
}...and也将由Buildship应用。
https://stackoverflow.com/questions/71712656
复制相似问题