Where should I put the main implementation in a multi module Maven project?
I have a small (4 module) maven project with the root pom in pom
packaging. Right now, I have a impl
module that contains the main methods and setup. This does lead to some issues, eg building a single jar for the entire project, (possible) huge dependency list containing all modules, and confusion trying to trace back to the main method for future developers.
So I'm thinking: Is it best practice to put this kind of stuff in the root project, or should it stay in its own module? Would there be any disadvantages of putting it 开发者_如何学编程in root (eg plugin issues)?
This does lead to some issues, eg building a single jar for the entire project
There are solutions for this (e.g. using a dedicated module and the Maven Assembly Plugin or the Maven Shade Plugin).
(possible) huge dependency list containing all modules,
I didn't understand what you're referring to here.
and confusion trying to trace back to the main method for future developers.
Just document things if nobody can transmit the information.
So I'm thinking: Is it best practice to put this kind of stuff in the root project, or should it stay in its own module? Would there be any disadvantages of putting it in root (eg plugin issues)?
Stephen is correct, aggregating and/or parent POMs must have a packaging of type pom
and you can't put any code in them.
AFAIK, the parent module of a multi-module project has to have type "pom" and that would preclude putting any code or other resources into it.
Certainly, I wouldn't try this.
If you want to have all of your classes, etc assembled into a single JAR, there are other ways of doing this. For example, take a look at the Maven Shade Plugin.
精彩评论