Apt fails to build twice in a row
I'm having a bit of a problem with apt, which seems to not want to build the same files twice without the genrated files being discared first.
I'm using the <apt> task in Ant 1.7 beta to build my source. My source contains both annotations and a custom annotation processor that is used to generate code that is in turn compiled into class files. Source and binary files generated during annotaiton processing are saved to a separate directory.
When I make clean and then compile my code, everything works fine. Howver, if I then attempt to compile again without cleaning, apt reports an error that is has been invoked with incorrect arguments. This is somewhat of a problem, since it interferes with incremental builds.
Is this expected behavior? How can I build incrementally?
This is what I have in my ant script. Ant simply formats the below tags and attributes into the appropriate command line and invokes it.
<apt debug="true" destdir="${classes.dir}" preprocessdir="${gen.dir}" compile="true">
<compilerarg value="-Xlint"/>
<src>
<path refid="path.sourcepath"/>
</src>
<classpath>
<path refid="path.classpath"/>
</classpath>
</apt>
Message was edited by:
Mark_McKay
What is the error you get?If it is something about a class being found twice, it may be that your $gen.dir is included on the sourcepath. It should not.Bruce
Not really an error message. Just the help message that is presented when apt gets incorrect input. My gen directory is not in my source path.
init:
prepareBuild:
compile:
Compiling 3 source files to C:\dev\svn.kitfox.com\kitfox-swing\build\classes
Usage: apt <apt and javac options> <source files>
where apt options include:
-classpath <path> Specify where to find user class files and annotation processor factories
-cp <path>Specify where to find user class files and annotation processor factories
-d <path>Specify where to place processor and javac generated class files
-s <path>Specify where to place processor generated source files
-source <release> Provide source compatibility with specified release
-versionVersion information
-help Print a synopsis of standard options; use javac -help for more options
-X Print a synopsis of nonstandard options
-J<flag>Pass <flag> directly to the runtime system
-A[key[=value]]Options to pass to annotation processors
-nocompileDo not compile source files to class files
-print Print out textual representation of specified types
-factorypath <path>Specify where to find annotation processor factories
-factory <class>Name of AnnotationProcessorFactory to use; bypasses default discovery process
See javac -help for information on javac options.
Message was edited by:
Mark_McKay
It would be good to see the command line that ant is generating.will ant -verbose show that?Bruce
Here's what Ant prints in verbose mode.It's not the command line exactly, but it gives the idea of what is passed:
Execute:Java13CommandLauncher: Executing 'C:\Program Files\Java\jdk1.6.0\bin\apt.exe' with arguments:
'-d'
'C:\dev\svn.kitfox.com\kitfox-directed-graph\build\classes'
'-classpath'
'C:\dev\svn.kitfox.com\kitfox-directed-graph\build\classes;C:\Program Files\Java\jdk1.6.0\lib\tools.jar'
'-sourcepath'
'C:\dev\svn.kitfox.com\kitfox-directed-graph\src\main\java'
'-g'
'-Xlint'
'-s'
'C:\dev\svn.kitfox.com\kitfox-directed-graph\build\gen'
'C:\dev\svn.kitfox.com\kitfox-directed-graph\src\main\java\com\kitfox\dgraph\editor\form\designer\package-info.java'
'C:\dev\svn.kitfox.com\kitfox-directed-graph\src\main\java\com\kitfox\dgraph\editor\form\package-info.java'
'C:\dev\svn.kitfox.com\kitfox-directed-graph\src\main\java\com\kitfox\dgraph\facade\package-info.java'
The ' characters around the executable and arguments are
not part of the command.
'C:\dev\svn.kitfox.com\kitfox-directed-graph\build\gen'does not look like a java source file name, does it?
No, that's the generation directory for source code. That's why it's preceded by the -s.
Hi Mark,
I just dumped all those args into a file (and stripped the quotes), and ran with "apt @marksargs"
and it didn't like it.
I played around a bit, and the only problem seems to be in the -classpath.
I got apt to parse the options sucessfully by quoting the whole classpath value. I suspect it is because of the space in "program files".
But that all seems odd, because if that were your problem, then you'd get it every time, not just during incremental build.
You might want to try the same trick (grab ant's output of the options, put them in a file, and invoke ant with @argfile ) in your environment (where the paths actually exist :) and play around and see what the cause is.
Sorry I can't be more helpful.
Bruce