Is there a way for a Maven project to inherit repo

2019-02-23 17:11发布

I know that it's possible to configure the section in a parent POM and have it apply to the sub-modules in a multi-module project. However, I'd like to have a separate POM to reference as a dependency so I can have a reporting configuration I can "mix in" to various projects without having to replicate my reporting configuration across multiple projects. (See "dependency POMs" here: http://sonatype.com/books/maven-book/reference/pom-relationships-sect-pom-best-practice.html)

For example, for my Widget project, I have a parent POM (widget-parent) with two sub-modules, widget-core and widget-web. I'd like to have a separate POM, static-analysis, that widget-parent depends on. static-analysis would have a block that would define Checkstyle and FindBugs reporting. When I build Widget, I would expect Checkstyle and FindBugs to be run on widget-core and widget-web.

If your solution only works in a particular version of Maven, let me know. We haven't upgraded to 3.x yet.

2条回答
叛逆
2楼-- · 2019-02-23 17:56

This supposedly works since Maven 3.5, which was released in spring of 2017; see the related issue.

Configuration defined in plugins under <build><pluginManagement> will be used under <reporting> too now.

Refer to the documentation for further info, if you don't know how plugin-management works in Maven.

查看更多
Melony?
3楼-- · 2019-02-23 18:06

With Maven 3 the reporting element in the pom is gone and replaced by a configuration element for the site plugin. You can then use the usual pluginManagement to define a configuration that is used everywhere. I would suggest to upgrade to Maven 3 in general anyway and this gives you another good reason..

Update: The reporting element has been brought back and works again with latest versions of the site plugin.

查看更多
登录 后发表回答