2

我有配置某些插件的父 pom

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

我有代表集成测试的 pom 树

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

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

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

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

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

我想知道有没有某种

<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 启动时只能启动应用程序服务器和部署目标一次。

4

2 回答 2

2

我不知道有一种机制可以完全满足您的需求。最好的办法是使用 build 部分中定义的插件定义父 pom,而不是 pluginManagement 部分。在这种情况下,插件配置将始终被定义。将配置添加到父配置文件意味着您可以对这些插件的激活进行一些控制。

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

<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。我最近回答了另一个问题,详细说明了如何执行此操作。

另一种选择是编写另一个插件,使用 Maven shared-io 将描述符应用于 pom,该描述符可以定义合并到 pom 中的任意配置。另一个答案描述了如何做到这一点。

于 2009-09-17T10:14:19.933 回答
0

AFAIK,没有办法声明可以在其他地方使用的插件包......但是有继承。

<plugins>在您的集成测试项目中使用该部分中的声明创建一个 pom<build>并从该 pom 继承如何?这看起来可行。

于 2009-09-17T10:11:10.157 回答