Configure Maven plugins to stick together

旧城冷巷雨未停 提交于 2019-12-01 10:47:56
Rich Seller

I don't know of a mechanism that does exactly what you need. Your best bet is to define a parent pom with those plugins defined in the build section, rather than the pluginManagement section. In this case the plugin configuration will always be defined. Adding the configuration to a profile in the parent means you can exercise some control over the activation of those plugins.

One refinement to consider is that you can control activation of a profile by the presence or absence of a file. This way you can define the profile in the parent, but have it deactivated in that project because of the marker file being present in the parent. Child projects would not have the marker file in their source, so the profile would be activated for those projects. You can reverse the behaviour by using missing instead of exists if that makes sense for the majority of projects.

<profile>
  <id>build</id>
  <activation>
    <file>
      <missing>src/main/resources/build.marker</missing>
      <!-- or if you want to enable the profile when the file does exist:
      <exists>src/main/resources/build.marker</exists-->
    </file>
  </activation>
  <build>
    </plugins>
      <plugin>
        <artifactId>gmaven-plugin</artifactId>
        ...
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        ...
      </plugin>
      <plugin>
        <artifactId>cargo-maven2-plugin</artifactId>
        ...
      </plugin>
    </plugins>
  </build>
</profile>

Alternatively, you could try writing custom plugin with a lifecycle that executes all the required mojos in a forked lifecycle. I recently answered another question with details of how to do this.

Another alternative is to write another plugin that uses Maven shared-io to apply a descriptor to the pom, that descriptor can define arbitrary configuration that is merged into the pom. Another answer describes how this can be done.

AFAIK, there is no way to declare a bundle of plugins that could be used somewhere else... but there is inheritance.

What about creating a pom with the <plugins> declaration in the <build> section and inheriting from this pom in your integration tests projects? This looks like feasible.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!