Extend maven cargo plugins jvmargs

吃可爱长大的小学妹 提交于 2019-12-11 04:59:39

问题


I have a maven project which extends an existing parent project (It's the "standard product" from which my product will be a "Customized product").

The parent declares a org.codehaus.cargo / cargo-maven2-plugin and passes it some VM args under configuration / cargo.jvmargs. Like this:

    <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>

Now in my custom project, I want to extend these jvm args with one more argument (Let's say -ArgD), so that the args are -ArgA -ArgB -ArgC -ArgD. I don't want to override the entire plugin only to do this one little change.

I know that I can specify this: cargo:run -Dcargo.jvmargs="-ArgD" but the problem here is: All other args (ArgA, ArgB, ArgC) get overridden/removed, only ArgD will remain. What I need is something like cargo:run -Dcargo.jvmargs="current_cargo.jvmargs + -ArgD".

Is this possible somehow?


回答1:


The cleanest possibility would be to move jvmargs in parent pom to maven property. Then in your custom project you would be able combine jvmargs using maven property with your custom values. For example:

Parent 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>

Your custom 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>

If there isn't possibility to modify parent pom you may use Cargo property cargo.start.jvmargs (see this page). This property add java arguments to container when it is started.



来源:https://stackoverflow.com/questions/38375693/extend-maven-cargo-plugins-jvmargs

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