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