如何从gradle中的eclipse .classpath中读取依赖项?(How to read the dependencies from an eclipse .classpath in grad

编程入门 行业动态 更新时间:2024-10-27 17:21:25
如何从gradle中的eclipse .classpath中读取依赖项?(How to read the dependencies from an eclipse .classpath in gradle?) java

这是eclipse .classpath文件的一个例子

<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src/main/java"/> <classpathentry kind="src" path="src/main/resources"/> <classpathentry kind="src" output="bin/test" path="src/test/java"/> <classpathentry kind="src" output="bin/test" path="src/test/resources"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/slf4j-api-1.7.7.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/slf4j-log4j12-1.7.7.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-collections4-4.0.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-codec-1.6.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-io-2.4.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-cli-1.2.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-net-3.3.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-lang-2.4.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/opencsv-2.3.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/log4j-1.2.17.jar"/> <classpathentry kind="output" path="bin/main"/> </classpath>

在gradle中,我想自动将这些添加到依赖项中。

有没有可以做到这一点的插件? (我知道我可以编写自己的方法来解析XML,但我正在寻找一些通用的方法)

here is a example of eclipse .classpath file

<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src/main/java"/> <classpathentry kind="src" path="src/main/resources"/> <classpathentry kind="src" output="bin/test" path="src/test/java"/> <classpathentry kind="src" output="bin/test" path="src/test/resources"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/slf4j-api-1.7.7.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/slf4j-log4j12-1.7.7.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-collections4-4.0.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-codec-1.6.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-io-2.4.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-cli-1.2.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-net-3.3.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/commons-lang-2.4.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/opencsv-2.3.jar"/> <classpathentry kind="lib" path="/kc-tools-thirdparty/lib/log4j-1.2.17.jar"/> <classpathentry kind="output" path="bin/main"/> </classpath>

In gradle I would like to automatically add these into dependencies.

Is there any plugin which could do that ? (I know I could write my own method to parse XML but I am looking for some general way)

最满意答案

我没有测试它,但我会做这样的事情:

//Init classpath file def classpathFile = file('.classpath') //parse xml def cpXml = new XmlParser().parse(classpathFile) //find all lib entries def libPaths= [] cpXml.classpathentry.each { if('lib' == it.@kind) { libPaths.add(project.projectDir.parentFile.absolutePath + it.@path) } } dependencies{ compile files(libPaths) }

I didn't test it but I would do something like this:

//Init classpath file def classpathFile = file('.classpath') //parse xml def cpXml = new XmlParser().parse(classpathFile) //find all lib entries def libPaths= [] cpXml.classpathentry.each { if('lib' == it.@kind) { libPaths.add(project.projectDir.parentFile.absolutePath + it.@path) } } dependencies{ compile files(libPaths) }

更多推荐

本文发布于:2023-07-15 22:06:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1119398.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:eclipse   gradle   classpath   dependencies   read

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!