扩展 maven cargo 插件 jvmargs

Extend maven cargo plugins jvmargs

我有一个扩展现有父项目的 Maven 项目(它是 "standard product",我的产品将成为 "Customized product")。

父级声明了一个 org.codehaus.cargo / cargo-maven2-plugin 并在 configuration / cargo.jvmargs 下传递了一些 VM args。像这样:

    <plugin>
      <groupId>org.codehaus.cargo</groupId>
      <artifactId>cargo-maven2-plugin</artifactId>
      <version>1.4.18</version>
      <configuration>
        <container>
          <containerId>tomcat8x</containerId>
          [...]
          <dependencies>
            [...]
          </dependencies>
        </container>
        <configuration>
          <properties>
            <cargo.jvmargs>-ArgA -ArgB -ArgC</cargo.jvmargs>
          </properties>
          <configfiles>
            [...]
          </configfiles>
          <files>
            [...]
          </files>
        </configuration>
      </configuration>
    </plugin>

现在在我的自定义项目中,我想用另一个参数(比方说 -ArgD)扩展这些 jvm args,这样 args 就是 -ArgA -ArgB -ArgC -ArgD。我不想为了做这个小改动而覆盖整个插件。

我知道我可以指定这个:cargo:run -Dcargo.jvmargs="-ArgD" 但这里的问题是:所有其他 args(ArgA、ArgB、ArgC)得到 overridden/removed,只有 ArgD 会保留。我需要的是 cargo:run -Dcargo.jvmargs="current_cargo.jvmargs + -ArgD" 之类的东西。

这有可能吗?

最干净的可能性是将父 pom 中的 jvmargs 移动到 maven 属性。然后在您的自定义项目中,您可以使用 maven 属性 将 jvmargs 与您的自定义值结合起来。例如:

父 pom:

<properties>
    <cargo.base.jvmargs>-ArgA -ArgB -ArgC</cargo.base.jvmargs>
</properties>
[...]
<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <version>1.5.0</version>
  <configuration>
      [...]
    <configuration>
      <properties>
        <cargo.jvmargs>${cargo.base.jvmargs}</cargo.jvmargs>
      </properties>
        [...]
    </configuration>
  </configuration>
</plugin>

您的自定义 pom:

<plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
      [...]
    <configuration>
      <properties>
        <cargo.jvmargs>${cargo.base.jvmargs} -ArgD</cargo.jvmargs>
      </properties>
        [...]
    </configuration>
  </configuration>
</plugin>

如果无法修改父 pom,您可以使用 Cargo 属性 cargo.start.jvmargs(参见 this page)。此 属性 在启动时向容器添加 java 参数。