Maven-父Pom-子继承 [英] Maven - Parent Pom - Child Inheritance

查看:286
本文介绍了Maven-父Pom-子继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试进行Maven父pom设置,而不必在子pom中声明任何插件信息,所有内容均取自父pom.

I am attempting to make a maven parent pom setup where I don't have to declare any plugin information in my child pom, everything is taken from the parent pom.

从本质上讲,我已经将所有带有配置的插件放入父pom了.然后在子poms中,我必须仍然声明插件,但是没有版本和配置信息.

I essentially have it working where I've put all my plugins with there configurations in to the parent pom. Then in the child poms I have to declare the plugin still, but without the version and configuration information.

我根本不需要在孩子中声明插件.这样,我可以向父pom添加新功能(例如pmd,freebugs等),并且我的所有项目现在都可以正常工作.我该怎么做?

I don't want to have to declare the plugin in the child at all. This way I can add new features (such as pmd, freebugs, etc) to my parent pom and all my projects now have them working. How can I accomplish this?

父Pom

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-scm-plugin</artifactId>
            <version>1.0</version>
            <inherited>true</inherited>
            <configuration>
                <providerImplementations>
                    <cvs>cvs_native</cvs>
                </providerImplementations>
                <systemProperties>
                    <property>
                        <name>maven.scm.perforce.clientspec.name</name>
                        <value>${perforceClientSpec}</value>
                    </property>
                </systemProperties>
            </configuration>
        </plugin>

儿童Pom仍需要此功能,但如果可以避免的话,我不想这样做:

Child Pom still needs this but I don't want to have to do this if I can avoid it:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-scm-plugin</artifactId>
</plugin>

推荐答案

<pluginManagement>部分旨在配置从其继承的项目构建.但是,这只会配置子元素的plugins元素中实际上引用的插件(因此,您必须按照指示明确指定它们).在此处更多.

<pluginManagement> section is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children (so you have to explicitly specify them, as you indicated). See more here.

如果要避免这种情况,可以将此信息放入<build>部分,如下所示:

If you want to avoid this, you can put this information into <build> section like this:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-scm-plugin</artifactId>
      <version>1.0</version>
      <configuration>
        <...>
      </configuration>
      <executions>
        <...>
      </executions>
    </plugin>
  </plugins>
</build>

这篇关于Maven-父Pom-子继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆