• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

maven-compiler-plugin: Is it possible to use a post-processed source directory?

 
Ranch Hand
Posts: 157
Netbeans IDE Postgres Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:

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).

Do you have a better idea? Thank you!
 
author & internet detective
Posts: 39343
755
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avor,
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.
 
Avor Nadal
Ranch Hand
Posts: 157
Netbeans IDE Postgres Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Posts: 39343
755
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Avor Nadal
Ranch Hand
Posts: 157
Netbeans IDE Postgres Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!