views:

89

answers:

3

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.

A: 

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.

1----->2
 |
 ----->3----->4

^      ^      ^
|      |      | 
A      B      C

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

disown
Yes, that's indeed what I like to do... so what is the solution? Ivy will require me to have the dependencies as part of the build script, but they will be available only from external metadata files... but not expressed as build.xml target or Ivy alternatives...
Egon Willighagen
What do you need help with exactly? You will need to write an ant plugin or use a scripting plugin to integrate your custom build solution with the existing one.
disown
Depending on the level of integration you might want to write an ant plugin, an ivy custom resolver, or something completely different. You need to specify your problem much clearer. For custom resolver, see http://ant.apache.org/ivy/history/2.0.0-alpha2/configuration/classpath.html
disown
Sorry for being confusing... what I am looking for is practical solutions, not theoretical ideas. Concrete code examples. I did ask for 'minimum custom code'... it's code I am after, not approaches.
Egon Willighagen
An ant extension may actually do the job... how would I start? Can you add a bit of example code in your answer to show how such can be used to read dependencies from an external file, and use that to on-the-fly create a build order?
Egon Willighagen
Would you like this build step to integrate with another dependency management system, or would you just like to have a standalone program or ant task to build these modules? Are they built with ant or with some custom build system, and are they all using the same build system?
disown
A: 

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.

openCage
The dependencies are listed in external files, and I cannot hardcode them in the build.xml.
Egon Willighagen
+2  A: 

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).

khmarbaise
Only problem is that topological sorting does not take parallel tasks into account, or have I missed something?
disown
How would that practically work? Can you point to a tutorial on how to write an implementation doing that? Perhaps something based on that Excalibur Framework (URL?) you mention...
Egon Willighagen