首页 > 解决方案 > Maven 在包含“-”时无法识别参数

问题描述

我试图在一个简单的 spring-boot 项目上测试这个maven 插件。但是我遇到了 mojo 参数的问题,当我使用包含“-”的参数和目标时,它似乎不起作用:

$ mvn clean install fabric8:build fabric8:resource \
> -Dfabric8.openshift.enableAutomaticTrigger=false \
> -Dfabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll=true

但是当我将这些参数作为系统属性放在项目的pom.xml. 它们似乎被 maven 插件选中并按预期工作。我像这样将它添加到 pom 中:

  <properties>
    <fabric8.openshift.enableAutomaticTrigger>false</fabric8.openshift.enableAutomaticTrigger>
    <fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>true</fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>
  </properties>

我在这里很困惑。谁能告诉我为什么它在以前的情况下不起作用?是否有某种我们应该遵循的 mojo 参数命名约定?

标签: javamaven

解决方案


我建议您使用一种解决方法(在我看来比调试 maven 更快的解决方案):

<properties>
   <f8.autoTrigger>your_default_here</f8.autoTrigger>
   <f8.enrichAll>your_other_default_here<f8.enrichAll>
   <fabric8.openshift.enableAutomaticTrigger>${f8.autoTrigger}</fabric8.openshift.enableAutomaticTrigger>
   <fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>${f8.enrichAll}</fabric8.enricher.fmp-openshift-imageChangeTrigger.enrichAll>
</properties>

如果你想覆盖你的默认值,你可以调用 maven,如:

$ mvn clean install fabric8:build fabric8:resource \
> -Df8.autoTrigger=false \
> -Df8.enrichAll=true

它甚至更短:)


推荐阅读