I am experimenting with using gradle’s ant import feature as the first step in migrating an old, large, and somewhat broken ant build to gradle. The problem I am having is because of bugs in this ant build and not because of bugs in gradle, but I’m sure it’s a problem others must have. In particular, there are cases in our ant build in which one task doesn’t declare a dependency on another task when it should, but the build works by luck because of the order in which ant happens to run the tasks. For example, if you run ‘ant x’ with this build.xml:
<project> <target name="x" depends="b,a"/> <target name="a"/> <target name="b"/> </project>
Buildfile: /tmp/z/build.xml b: a: x: BUILD SUCCESSFUL Total time: 0 seconds
but if you create this build.gradle:
and run ‘gradle x’, you see
:a :b :x
It seems that ant is running the independent dependencies of x in the order in which they were listed in the depends task (b and a) where gradle is running them alphabetically subject to the topological sort of the DAG.
There’s no question in my mind that what gradle is doing is correct. It is clearly correct. After all, who says there isn’t another task “y” that depends on “a,b” in that order instead? Even ant doesn’t guarantee the order in which two independent tasks will run even if it happens to do it in a particular way.
At the same time, if it so happens that “a” fails unless “b” is run first and “a” fails to declare a dependency on “b”, then the imported build will fail even if the original build succeeds, and this creates an impediment to migrating.
Is this a pattern people have run into before? Is there a standard workaround in place? Has anyone produced anything that will look at an ant build figure out what order the targets would be run in, and compares this to the order gradle would run the imported tasks in given a particular task? In this particular instance, it’s pretty easy to see that if the “x” task is given on the command line, ant and gradle would behave differently. Getting a list of such cases might help someone trying to fix the old build to identify places where dependencies might be missed.
If there’s nothing currently in existence to help with this, I’m sure I can do the analysis on the old build, but I thought I’d ask before I reinvent the wheel.