1

Say a Maven project has a cool build plugin configured:

<project>
    ...
    <build>
       ... extensions etc.
    </build>
    ...
</project>

I want this configuration to be reusable, so that I can run the goals provided by the plugins/extensions in any new project. The above project might exist just so that other projects can reuse the config.

What is the best way to achieve this?

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
Parobay
  • 2,549
  • 3
  • 24
  • 36

2 Answers2

3

Use a parent.pom. Deploy this pom to your local repository. Of course you could configure parent.poms for each type of project that you regularly develop in your organisation. Probably a master.pom with general values (location of servers, organisation name, general code style...) is a good idea. The project specific poms would use this as parent.

Hauke Ingmar Schmidt
  • 11,559
  • 1
  • 42
  • 50
  • In a multiproject project, the "plugin parent" should be the parent of the main, top-level pom, right? What If I want to add this behavior to a single child (module) of the main pom, not do all modules? It already has a parent (the top-level pom)... – Parobay Jan 07 '14 at 07:58
  • 1
    Yes, in that case only the top level `pom` can have an external parent, the modules inherit via this but you can't give modules individual behaviour this way. This method works only with projects. Sometimes this is a hint that a module could be a project instead (but not always, sadly). – Hauke Ingmar Schmidt Jan 07 '14 at 08:08
2

Declare this pom.xml as of type pom:

<type>pom</type>

and declare it as a parent in every "child" pom.xml that needs the configured plugins: http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance

Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148