maven - 如何将 env var arg 传递给 maven 到 shell 脚本?
问题描述
我正在使用 exec 插件从 maven 调用 shell 脚本,并希望将 arg 传递给我的 maven 命令,该命令将被转发到 shell 脚本。所以如果我这样做
mvn exec:exec compile -Dfoo=bar
我希望能够在我的 shell 脚本中使用 foo 访问$foo
. 我尝试使用${env.foo}
and将它作为参数从 pom.xml 传递给 shell 脚本${foo}
,但我总是在 shell 脚本中得到那些确切的文字而不是“bar”,它 foo 也应该扩展。
我的 pom.xml 就像
<build>
<plugins>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>asdf</groupId>
<version>1</version>
<executions>
<execution>
<id>asdf</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>bash</executable>
<commandlineArgs>myscript.sh ${env.foo}</commandlineArgs>
</configuration>
</plugin>
</plugins>
</build>
解决方案
您可以使用arguments
orcommandlineArgs
配置。
关键是您必须为以下foo
任一项提供值:
- 在命令行上:
-Dfoo=bar
- 通过定义一个属性:
<properties><foo>bar</foo></properties>
例如:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<executable>bash</executable>
<arguments>
<argument>myscript.sh</argument>
<argument>${foo}</argument>
</arguments>
</configuration>
</plugin>
然后跑...
mvn exec:exec -Dfoo=bar
... 将导致myscript.sh
使用一个参数运行:foo
.
注意:您问题中的插件配置看起来不正确。具体来说; ( groupId
"asdf") 和version
(1)。
推荐阅读
- google-apps-script - ReferenceError: "e" 未定义 | 仅在一张纸上运行多个脚本的困难
- microservices - 事件驱动微服务架构的可用性计算
- android - 依赖组件的匕首注入
- sql - 在一个查询中加入 2 个选择
- c++ - 在 C++ 中使用元组作为元素访问元组
- javascript - JavaScript 不适用于 bootstrap 4 + thymeleaf
- php - .htaccess 允许执行 php 文件
- c# - 使用 VSTO 使在 C# 中创建的类型可以从 vba 访问
- c++ - 如何解决 OpenGL/GLSL 上的观察矩阵问题
- swift - 从 compactMap 返回和退出