You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by jeff <jl...@houseofdistraction.com> on 2000/10/10 19:21:57 UTC
dependencies in Ant?
I have been evaluating Ant to decide if we should use it but I can't
find anything in the docs or example build files that addresses the
following situation.
Consider these files all in the same directory:
---------
A.java
---------
public class A
{
B b;
public A()
{
b = new B( 3 );
}
}
---------
B.java
---------
public class B
{
int x;
public B( int x )
{
this.x = x;
}
}
---------
build.xml
---------
<?xml version="1.0"?>
<project name="test" default="compile" basedir=".">
<target name="compile">
<javac srcdir="." classpath="." destdir="." />
</target>
</project>
I type "ant", it builds A.class and B.class, everything is happy. Now I
change B
---------
B.java
---------
public class B
{
Integer x;
public B( Integer x )
{
this.x = x;
}
}
I type "ant", it builds B, it says everything is happy but we know
better. If I were to touch A.java and invoke Ant again it would give me
the bad news.
I would like to set up a build file so that the builds are always
automatically correct. This is the best I could figure out for this
example:
---------
build.xml
---------
<?xml version="1.0"?>
<project name="test" default="compile" basedir=".">
<target name="compile" depends="nuke-A">
<javac srcdir="." classpath="." destdir="." />
</target>
<target name="nuke-A">
<delete file="A.class" />
</target>
</project>
This technique works but it has a two obvious problems:
1. Files with dependencies are always recompiled. In a large
project this would be most of the files.
2. It is tedious to set up and maintain.
Now, I could imagine addressing problem #2 by periodically using jikes
+M and post-processing the resulting .u files into a new build.xml but I
can't see any way to address problem #1 using Ant. How do people deal
with this in real projects?
Re: dependencies in Ant?
Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "j" == jeff <jl...@houseofdistraction.com> writes:
j> I type "ant", it builds B, it says everything is happy but we know
j> better. If I were to touch A.java and invoke Ant again it would
j> give me the bad news.
Ant is not that clever yet - but this might change in the future. To
be extra sure you'll probably do a "ant clean" before you compile.
I've found that I rarely change interfaces or base classes after a
project has evolved so Ant's current approach (compile all .java files
that are newer than the .class files) is exactly what I need most of
the time.
In the rare occasions where this is not enough I take the extra time
to recompile the whole project (and I know when this needs to be
done).
Stefan
Re: dependencies in Ant?
Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "DS" == Dan Smith <da...@globalone.net> writes:
DS> <javac srcdir=".:${src.dir}"
Is this intentional, I mean adding .: to srcdir? I assume you know Ant
expects srcdir to point to the root of a class hierarchy where the
directory structure matches the package structure.
If ${src.dir} points to a directory somewhere below . your .java files
will be found twice, once inside . and once in ${src.dir} - and while
${srcdir} might be set up to suit Ant's expectations . will probably
not.
Stefan