Can you refactor Maven pom.xml files into reusable XML fragments?

In Maven, is it possible to refactor commonly repeated fragments into a reusable "library" (plugin)? I realize that I can write my own plugins, but often the functionality I want to re-use is already expressed as fragments in a pom.xml, and my natural inclination is that the mechanism of re-use should preserve those fragments as XML.

Case in point I've been using a procedure (partly described here) for generating a WADL file from Jersey/JAX-RS source code, and then generating developer documentation from that WADL and the source-code's own Javadoc. The procedure on that page describes the execution of two plugins, and I am using a third plugin (org.codehaus.mojo:exec-xsltproc) and my own XSL file to turn the WADL into HTML.

I've used this procedure in several Maven projects. The boilerplate comes in at 100 lines of XML. What changes between projects is simply the package name of the source code in question (com.example.myapp.rest in the linked boilerplate). Therefore it is not possible to move this into a parent pom, or any other mechanism that does not allow parametrization.

What I want is to aggregate, template-out, or otherwise refactor those 100 lines (and one XST file) into a common location. I realize that re-usable maven executions are delivered via Maven plugins. Ideally I wouldn't have to write any Java (or Groovy) just to re-express what I have already expressed in XML.

Is it possible to refactor Maven pom.xml files as XML?

8
задан Matt Quail 9 May 2011 в 11:07
поделиться