首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将模块导出添加到Eclipse文件中

将模块导出添加到Eclipse文件中
EN

Stack Overflow用户
提问于 2022-04-01 20:53:51
回答 1查看 277关注 0票数 0

我有一个较旧的项目,它需要在Eclipse的.classpath文件中导出一个模块,这样它就可以从这个模块解析一些类。如果通过Eclipse的构建路径编辑器生成类路径条目,则类路径条目如下所示:

代码语言:javascript
复制
<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生成这个条目,我终于做到了:

代码语言:javascript
复制
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中创建一个容器,并向它添加属性,这是我无法做到的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-05 10:04:34

我找到了解决方案,属性节点可以通过entryAttributes field of the AbstractClassEntry class访问。

这样,我就可以.

代码语言:javascript
复制
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应用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71712656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档