配置Maven插件以将其粘合在一起 [英] Configure Maven plugins to stick together

查看:70
本文介绍了配置Maven插件以将其粘合在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有配置某些插件的父pom

I have parent pom which configures certain plugins

<pluginManagement>
   </plugins>
      <plugin>
         <artifactId>gmaven-plugin</artifactId>
         ...
      </plugin>
      <plugin>
         <artifactId>maven-resources-plugin</artifactId>
         ...
      </plugin>
      <plugin>
         <artifactId>cargo-maven2-plugin</artifactId>
         ...
      </plugin>
   </plugins>
</pluginManagement>

我有代表集成测试的poms树

And I have tree of poms which are represent integration tests

A-\
   a1
   a2
B-\
   b1
   b2
C-\
   D-\
      d1
      d2

我做的每个a,b,d产品

In each a,b,d products I do

<build>
   <plugins>
      <plugin>
         <artifactId>gmaven-plugin</artifactId>
      </plugin>
      <plugin>
         <artifactId>maven-resources-plugin</artifactId>
      </plugin>
      <plugin>
         <artifactId>cargo-maven2-plugin</artifactId>
      </plugin>
   </plugins>
</build>

问题是,当我需要将第四个插件添加到集成测试过程中时,例如我需要移动的自定义插件 通过所有集成模块并手动添加.

The problem is when I will need to add fourth plugin to integration test process for example my custom plugin I will need to move through all of the integration modules and do manual adding.

您可以建议我删除<pluginManagement>,以允许所有孩子仅隐式使用它们. 是的,但是在仅仅是"pom"的产品中,我不希望插件做任何事情:创建一些资源并放置jboss配置目录.

You can advice me to remove <pluginManagement> to allow all child just to use them implicitly. Yes, but in products which are just 'pom' I don't want plugins to do anything: create some resources and put jboss configuration directories.

我想知道是否有

<pluginsBundle>
   <groupId>my.group</groupId>
   <artifactId>my-integration-test-bundle</artifactId>
   <plugins>
      <plugin>
         <artifactId>gmaven-plugin</artifactId>
      </plugin>
      <plugin>
         <artifactId>maven-resources-plugin</artifactId>
      </plugin>
      <plugin>
         <artifactId>cargo-maven2-plugin</artifactId>
      </plugin>
   </plugins>
</pluginsBundle>

允许我像

   <plugin>
      <groupId>my.group</groupId>
      <artifactId>my-integration-test-bundle</artifactId>
      <runOnce>true</runOnce>
   </plugin>

我想添加类似的选项

<runOnce>true</runOnce>

每次启动Maven只能启动应用程序服务器和部署目标一次.

to be able to start application server and deploy target only one time per maven launch.

推荐答案

我不知道一种能完全满足您需要的机制.最好的选择是使用build部分(而不是pluginManagement部分)中定义的那些插件来定义父pom.在这种情况下,将始终定义插件配置.将配置添加到父级的配置文件中意味着您可以对这些插件的激活进行一些控制.

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.

要考虑的一种改进是,可以通过存在或不存在文件来控制配置文件的激活.这样,您可以在父级中定义配置文件,但是由于在父级中存在标记文件,因此在该项目中将其停用.子项目的源中将没有标记文件,因此将为那些项目激活配置文件.如果对大多数项目有意义,则可以使用missing而不是exists来逆转该行为.

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>


或者,您可以尝试编写具有生命周期的自定义插件,该插件会在派生的生命周期中执行所有必需的mojo.我最近回答了另一个问题,其中包含有关操作方法的详细信息.


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.

另一种替代方法是编写另一个使用Maven shared-io来应用描述符的插件 对于pom,该描述符可以定义合并到pom中的任意配置.另一个答案描述了如何做到这一点完成.

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.

这篇关于配置Maven插件以将其粘合在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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