Maven - 父Pom - 儿童继承

Bel*_*ini 20 maven

我试图建立一个maven父pom设置,我不必在我的孩子pom中声明任何插件信息,一切都取自父pom.

我基本上把它放在我将所有插件都配置到父pom中的地方.然后在子poms我必须声明插件仍然,但没有版本和配置信息.

我根本不想在孩子中声明插件.通过这种方式,我可以向我的父pom添加新功能(例如pmd,freebugs等),现在我的所有项目都可以使用它们.我怎么能做到这一点?

父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>
Run Code Online (Sandbox Code Playgroud)

Child Pom仍然需要这个,但如果我可以避免,我不想这样做:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-scm-plugin</artifactId>
</plugin>
Run Code Online (Sandbox Code Playgroud)

And*_*nov 30

<pluginManagement>section旨在配置从此继承的项目构建.但是,这只配置在子节点的plugins元素中实际引用的插件(因此您必须明确指定它们,如您所示).在这里查看更多.

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

<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>
Run Code Online (Sandbox Code Playgroud)

  • @Nishant进一步解释了为什么这有效.默认情况下,子项POM继承了在`<pluginManagement>`之外声明的插件.如果需要,每个孩子都可以覆盖他们的设置.在`<pluginManagement>`中声明的插件为显式配置为使用这些插件的所有子POM配置全局设置(如原始示例中所示).它们的设置也可以在子POM中被覆盖. (2认同)

Nis*_*ant 14

而不是使用pluginManagement,尝试使用<plugins>标签.它应该是自动继承的.您可以选择覆盖子pom中的配置.检查一下mvn help:effective-pom