【问题标题】:Run Maven goal only in parent POM by activation通过激活仅在父 POM 中运行 Maven 目标
【发布时间】:2016-06-05 23:27:36
【问题描述】:

我正在将一个插件集成到一个多模块项目中。

我正在使用一个 3rd 方插件,它基本上只需要从父项目运行(基于我对它的理解和使用)。我尝试通过使用profile 来完成此操作,如下所示:

<profiles>
    <profile>
        <id>run-my-guy</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.myproject</groupId>
                    <artifactId>myproject-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>runThing</goal>
                            </goals>
                            <inherited>false</inherited>
                        </execution>
                    </executions>
                    <inherited>false</inherited>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

我有几个&lt;inherited&gt;false&lt;/inherited&gt;,但如果我运行mvn help:all-profiles,我仍然可以在每个模块中看到这个配置文件。如果我运行我的mvn package -P run-my-guy,我会看到它在每个子项目中执行。我希望能够激活它,但我不希望它默认开启。

如果我尝试将其添加到 &lt;build&gt; 部分,如下所示:

<build>
  <plugins>
    <plugin>
      <groupId>com.myproject</groupId>
      <artifactId>myproject-maven-plugin</artifactId>
      <inherited>false</inherited>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>runThing</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

在这里,我也有几个&lt;inherited&gt;false&lt;/inherited&gt;,只是为了尝试强制插件和执行不被继承。但是,当我运行 package 阶段或包含该阶段的任何内容时,会包含 runThing 目标。

如何仅通过激活(如配置文件或其他功能,或仅通过显式运行目标)并仅在父级中运行目标?

【问题讨论】:

    标签: maven


    【解决方案1】:

    "Run a single Maven plugin execution?" 的答案所示,现在可以(从 Maven 3.3.1 开始)为直接目标调用指定执行 ID。

    pom.xml

    <build>
      <plugins>
        <plugin>
          <groupId>com.myproject</groupId>
          <artifactId>myproject-maven-plugin</artifactId>
          <inherited>false</inherited>
          <executions>
            <id>myproject-exec-id</id>    <!-- note the execution Id -->
            <execution>
              <phase>none</phase>
              <goals>
                <goal>runThing</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
    

    然后从命令行调用目标使用可选的@executionId 参数:

    mvn myproject:runThing@myproject-exec-id
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-17
      • 2017-01-02
      相关资源
      最近更新 更多