I want to know it it's possible, with Maven, to post-process the original source files of my project, generate the resulting files in an intermediate source directory, and make "maven-compiler-plugin" to compile from there instead of from the original directory. By "post-process" I mean to process the source files with something that replaces text sequences, be it a custom plug-in or a typical command such as sed or perl. But my question is not related to this last point, but to configuring the directory.
With Ant it's moderately easy. But with Maven, it doesn't seem so. I prefer not to change the <sourceDirectory> tag in <build>, because I still want that the original directory is the reference one. One of the reasons for this is that NetBeans, which is the IDE that I'm using, wouldn't show the original files in its project panel, but the post-processed ones. I couldn't edit the original files with ease. I would lose the ability to refactor, the automatic dependency check, etc.
One idea that I've had is to try with the <includes> configuration parameter of the maven-compiler-plugin. But I've read that it was deprecated several versions ago.
Another idea is to use the build-helper-maven-plugin and its add-source goal. To add the directory of post-processed files as an additional source, and expect that the compiled files overwrite the ones of the original. However, the compiler actually fails indicating that the classes are duplicated (I've just tested it).
If I was was doing this, I'd use the antrun plugin. That lets you run at you can specify at what point in the cycle it should happen. I don't know how to change the source directory so I'd probalby use ant run to cheat and do it in two parts:
1) pre-compile - back up original source and do text post-processing
2) post-compile - restore original source
This doesn't seem like a clean way though so I'm curious to see if people come up with something better.
Thank you for answering me, Jeanne. That's something that I also considered at the beginning. But I ruled the possibility out because, as you mention, it didn't seem clean/elegant. Specially because NetBeans notices the changes in the files and you can see how it re-scans the file tree. But I've to admit that, among all the options presented here, it's the only one that would really work. At least until someone presents a cleaner way, of course.
After three days of no replies, I suspect there isn't a better approach. Which is certainly possible. Maven is big on "the Maven way". And then the IDE doesn't exist so it isn't a problem to change the files in the original source directory.
Jeanne Boyarsky wrote:After three days of no replies, I suspect there isn't a better approach. Which is certainly possible. Maven is big on "the Maven way". And then the IDE doesn't exist so it isn't a problem to change the files in the original source directory.
Yes, I guess there isn't any other solution. I'll have to conform to the way of doing things of Maven, or to go back to Ant. Thanks!