Java代码将依赖项列表转换为构建顺序?
鉴于我有一个依赖项列表,可用作外部文件中的位。这些将被聚合到一个列表中,例如:
module1
module2 dependsOn module1
module3 dependsOn module1
module4 dependsOn module3
我想创建一个构建顺序,其中每个构建步骤都在一行上找到,并且每一行包含一个或多个可以同时编译的模块的列表,并且仅依赖于之前编译的模块。
因此,对于上述数据集,创建一个列表,如下所示:
module1
module2,module3
module4
现在,这基本上只是创建有向图并分析它的问题。现在,我正在使用 Ant,并且非常想使用现成的东西......什么是我需要让它从给定输入开始创建这样一个依赖项感知构建列表的最少自定义代码吗?我不想自己编写所有代码(我知道该怎么做),但在这里寻找库来帮助我...
顺便说一句,这些模块实际上是自定义模块,所以 Maven 将无法工作。此外,模块列表是从 Java 源代码动态创建的,我无法在构建文件中对其进行硬编码。
Given I have a list of dependencies available as bits in external files. These will be aggregated into a list like:
module1
module2 dependsOn module1
module3 dependsOn module1
module4 dependsOn module3
I would like to create a build order where each build step is found on one line, and each line contains a list of one or more modules which can be compiled at the same time, and which only depend on modules compiled earlier.
So, for the above data set, create a list like:
module1
module2,module3
module4
Now, this is basically just a problem of creating a directed graph, and analyzing it. Now, I am using Ant, and would very much like to use something off-the-shelf... what is the minimum of custom code I need to have it create such a dependency-aware build list starting from the given input? I do not want to write all code myself (which I know how to do), but looking for libraries to help me here...
BTW, these modules are actually custom modules, so maven will not work. Moreover, the module list is created on the fly from the Java source code, and I cannot hard code this in the build file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用拓扑排序来查看真实的排序情况。这可以通过使用 unix util tsort 来完成,或者您可以搜索拓扑排序的实现(Excalibur Framework 有类似的东西)。
You can use topological sorting to see how the real ordering is. This can be done by using unix util tsort or you can search for an implementation for toplogical sort (Excalibur Framework has something like this).
Ant 可以为您处理。您基本上将模块依赖项描述为目标依赖项。
看看 [http://stroy.wikidot.com/motpe]。这是两个具有相同约定的 Ant 脚本
处理多模块构建。
Ant can handle that for you. You basically describe your module dependencies as target dependencies.
Have a look at [http://stroy.wikidot.com/motpe]. It is 2 ant scripts with same conventions
to handles multi module builds.
绘制一个依赖关系树并查看各个级别。您可以从根开始构建,并并行构建树的每个级别(假设上面的级别已经构建)。
首先构建 A(模块 1),然后构建 B(2 和 3),然后构建 C(4)。
编辑:
如果您正在使用 Ant 并且专门要求 Ant 的依赖关系解析解决方案,您可以查看 Apache Ivy
Draw a tree of your dependencies and look at the levels. You can start building at the root and build each level of the tree in parallel given that the levels above are already built.
Build A first (module 1), then B (2&3), then C (4).
EDIT:
If you are using Ant and are asking specifically for a dependency resolution solution for Ant, you could take a look at Apache Ivy