ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Duncan Davidson <>
Subject FW: Suggested Ant dependency feature
Date Wed, 24 Jan 2001 22:36:29 GMT

James Duncan Davidson                              
                                                                  !try; do()

------ Forwarded Message
From: Mike <>
Date: Wed, 24 Jan 2001 16:38:18 -0500
Subject: Suggested Ant dependency feature

  I used to use a Makefile in combination with a shell-script that would
look at the previously generated .class files and turn them into
depencies on the .java files, like so:
something.jar: $(SRC)
  rm -rf tmp
  mkdir tmp
  jikes +E +F -d tmp $(SRC)
  cd tmp;jar cfM ../$@ .
  javadeps tmp Makefile
## dependencies:
something.jar: \
  com/myself/app/ \
The shell-script 'javadeps' peruses the tmp directory and searches for
all .class files.  Each one it finds it tries to find a corresponding
.java file.  If found (not found in case of inner classes), it puts it
in the Makefile.
This works absolutely perfect!  It is always aware of other java files I
'import' without me having to list them manually, which would be
certainly very error prone, since you're bound to forget them.  I also
only specify the application's entry point.  The compiler will
automatically compile all the other .java files precisely, no more .java
files are compiled and included in my .jar file then are necessary.
Ok, now using *Ant*:
<project name="something" default="all" basedir=".">   <target
name="all" depends="init,compile_classes" />   <target name="init">
    <property name="build.compiler" value="jikes"/>   </target>
  <target name="compile_classes" depends="init">     <mkdir dir="tmp"/>
    <javac srcdir="."
    <jar jarfile="something.jar" basedir="tmp"/>   </target>
This generates the something.jar ok.
Now, here's the problem:
If I modify com/myself/io/ and run *Ant* again, it
doesn't compile!  It doesn't look into the tmp folder and doesn't see
that there is a dependency on the com/myself/io/
file.  If I modify the file it's ok, it'll recompile but not
if I touch other files that aren't listed.
Listing it in the 'includes' attribute is unacceptible, because there
are like 40 files in it.  Listing the .java file explicitly is also
unacceptible because how do I know I didn't forget anything.  Deleting
tmp before the compile is not great because it then always compiles
So I suggest *Ant* gets a new feature where you can make it scan the tmp
folder for other previously generated .class files that weren't listed
and tries to match them up to the source.

In the meantime I found a workaround:

I have a bash script with the following:

dir=$1 target=$2

if [ ! $dir ] || [ ! $target ]
   echo Usage: antdep \<classdir\> \<target>\


cd $dir
files=`find . -name "*.class"`
cd $here
for a in $files
   if [ ${a/.class/.java} -nt $dir/$a ]
       echo ${a/.class/.java} is newer than $dir/$a, removing $dir/$target
       rm -f $dir/$target

In build.xml I add:

   <target name="deps">
       <exec dir="." command="./antdep tmp com/myself/app/Test.class"/>

I make the deps target a dependency.  So, now everytime I run 'ant', the
script ends up deleting my .class file if any of my .java files in
question are newer than the .class file in tmp.
So, I'm hoping Ant will have this feature built in the next release?


------ End of Forwarded Message

View raw message