How to create reusable configuration in maven?

I have a java project using maven with several submodules that build the same way: there is an executable jar, dependency bans in the lib directory, some resources, etc.

The configuration between the modules differs only in the main class. Therefore, I want to create some kind of pre-configured assembly (or macros or something else) so as not to copy the same configuration of the assembly plugins into different pom.xml modules, but to reuse the same configuration with the main class as a parameter.

How can i achieve this?

(Build Configuration: http://pastebin.com/9Fm5rFK7 )

+4
source share
1 answer

You can parameterize them using maven properties , override them after inheriting . In your case, you can enter the mainClass property and use it in your plugin configuration from the parent module, for example, <mainClass>${mainClass}</mainClass> . These properties can then be overridden in child modules.

EDIT:
For the parent pom, I meant the pluginManagement section (Sorry for the fuzziness). I created an example with your build configuration here: https://gist.github.com/ceilfors/5827916

I think the minimum you can get in a child module. maven-jar-plugin is optional due to the type of packaging in the jar. Refer to the lifecycle bindings and you can see that the plugin will be called during the package phase.

In addition, when your project becomes more complex, you can learn how to integrate the plugin configuration. I created another example here: https://gist.github.com/ceilfors/5828039 . Note that the properties for mainClass were not used.

Hope this helps.

+2
source

Source: https://habr.com/ru/post/1486889/


All Articles