JCS
JCS

Reputation: 907

Ant compiling packages that are dependent

I recently started to learn ant and have ran into some trouble, i basically have 2 packages and am trying to compile both, but both packages consist of java files which depend on each other(e.g. a.java from package1 is dependent on b.java from package2 and vice versa) hence i cant compile one with out the other for example below.

<?xml version="1.0"?>
  <project name="exampleproject" basedir="." default="compile">
  <property name="src1" value="package1"/>    
  <property name="src2" value="package2"/> 
  <property name="dest" value="build"/>
  <property name="classpath" value="${dest}"/>
<target name="clean">
    <delete dir="${dest}"/>
</target>
<target name="build" depends="clean">
    <mkdir dir="${dest}"/>
</target>
<target name="compile" depends="clean,build">
      <javac srcdir="${src1}" destdir="${dest}"
         classpath="${classpath}"
         includeantruntime="false">
       </javac>
       <javac srcdir="${src2}" destdir="${dest}"
         classpath="${classpath}"
         includeantruntime="false">
       </javac>
</target>
</project>

From testing this does not work as when a try to compile package1 the build fails as there are classes in package2 yet not compiled, the only solution i have is to restructure my program, anybody have any better ideas on how to solve this problem?

Thanks.

Upvotes: 1

Views: 2771

Answers (2)

Valentin Kovalenko
Valentin Kovalenko

Reputation: 486

According to http://ant.apache.org/manual/Tasks/javac.html:

javac's srcdir, classpath, sourcepath, bootclasspath, and extdirs attributes are path-like structures and can also be set via nested (note the different name!), , , and elements, respectively

So you can use

  <javac destdir="${dest}" classpath="${classpath}" includeantruntime="false">
    <src path="${src1}"/>
    <src path="${src2}"/>
  </javac>

Upvotes: 3

jabal
jabal

Reputation: 12347

You have run into a circular dependency issue that is simply not solvable. You should reorganize your modules so that there is no dependency loop in it. It is usually a good start to move co-dependencies into a third new module or kind of. This is how xy-commons modules are born.. :-)

Upvotes: 2

Related Questions