Reputation: 5790
I have java project building using maven with several sub-modules that are build the very same way: there is executable jar, dependency jars in lib directory, some resources etc.
Configuration among modules differs only in main-class. So, I want to create some sort of preconfigured build (or macros, or whatever) to not copy same configuration of build plugins to different pom.xml modules but to reuse same configuration with main-class as a parameter.
How can I achieve this?
(Build configuration: http://pastebin.com/9Fm5rFK7)
Upvotes: 5
Views: 2466
Reputation: 2737
You can parameterized them with maven properties, override them after it is inherited. In your case, you can introduce mainClass property and use it in your plugin configuration from the parent module, for example <mainClass>${mainClass}</mainClass>
. This properties then can be overridden in the child modules.
EDIT:
For the parent pom, I was referring to the pluginManagement section (Sorry for the unclearness). I have created an example with your build configuration here:
https://gist.github.com/ceilfors/5827916
I think that's the minimum that you can get in the child module. maven-jar-plugin
is optional because of the jar packaging type. Refer to the lifecycle bindings and you can see that the plugin will be called during package
phase.
Also, when your project gets more complex, you can explore on how to merge the plugin configuration too. I have created another example here: https://gist.github.com/ceilfors/5828039. Note that properties for mainClass was not used.
Hope this helps.
Upvotes: 3