我有一個較舊的專案,它需要在 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 執行“重繪 Gradle 專案”時無效 - 因為這不考慮withXml. 所以我需要在其中創建一個 ContainerwhenMerged并為其添加屬性,這是我無法做到的。
uj5u.com熱心網友回復:
我找到了解決方案,可以通過entryAttributesAbstractClassEntry 類的欄位訪問屬性節點。
這樣,我只能做...
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'
}
}
}
...它也將被 Buildship 應用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/457472.html
上一篇:創建專案失敗。JDK9 不支持clientBuilder.sslSocketFactory(SSLSocketFactory)。EclipseOxygenEEjdk1.8.0u301
