Skip to Content

Querying for dependent projects?

Posted in

Hey guys,

Is there an ant4eclipse target that lets you query for which projects a given project depends on?

For instance, I'd like to make a macro (something like <buildJdtProjectRecursive>) that builds a project and any sub-projects it depends on. However, I can't seem to find any way to get a list of dependent projects.

Project dependencies appear to be tracked in .classpath:

  <classpathentry combineaccessrules="false" kind="src" path="/project-i-depend-on"/>

Is there a way to get these that I'm overlooking? buildJdtProject doesn't compile them automatically, and getJdtSourcePath seems to ignore them as well.

Alternatively, is there some flag to <buildJdtProject> to tell it to build recursively?



Hi Gordon,

you can use the - yet undocumented - getUsedProjects task:

<ant4eclipse:getUsedProjects workspaceDirectory="${workspaceDirectory}"
                                 separator="#" />

The reason why this task is not documented is that it is an 'old-style' task that only sets a property (or a path) but doesn't let you iterate over the projects. To do so, you have to use the ant-contrib task (for or foreach)

Hope that solves your problem...


In case anyone comes looking

In case anyone comes looking for this later, here is a simple recursive build macro. Requires ant-contrib-1.0b3.jar and xmlns:ac="antlib:net.sf.antcontrib".

Usage: <buildJdtProjectRecursively projectName="myproject" />

  <macrodef name="buildJdtProjectRecursively">
    <attribute name="projectName" />
    <attribute name="prefix" default="buildJdtProjectRecursively"/>
      <!-- Recursively build dependent projects -->
      <ant4eclipse:getUsedProjects workspaceDirectory="${workspaceDirectory}" projectName="@{projectName}" property="@{prefix}.usedprojects" separator="," />
      <ac:for param="usedProjectName" list="${@{prefix}.usedprojects}" delimiter=",">
          <buildJdtProjectRecursively projectName="@@{usedProjectName}" />
      <!-- Build the project itself -->
      <buildJdtProject workspaceDirectory="${workspaceDirectory}" projectName="@{projectName}" />


Thank you!

Thanks for the info, that's exactly what I needed!

I also found this open Jira issue discussing the upcoming getReferencedProjects/getProjectDependencies tasks. It sounds like they will do something similar.

getUsedProjects is a million times better than what I had, which was a macro using getJdtClassPath and regular expressions to parse project names out of non-jar classpath entries. :)