【问题标题】:How can I use command line arguments in the pom?如何在 pom 中使用命令行参数?
【发布时间】:2021-08-21 03:03:27
【问题描述】:

我有一个多模块项目,其中包含很多花里胡哨的东西。例如这个插件:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>${maven.exec.version}</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>python3</executable>
                            <workingDirectory>src/main/python</workingDirectory>
                            <arguments>
                                <argument>aggregate.py</argument>
                                <argument>${}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

从命令行,我们可以传递-q aka --quiet 之类的标志。对于aggregate.py 的第二个参数,我如何将-q 标志或任何其他标志传递到python 脚本中,以便它在运行时也能服从日志级别的请求?

如果我们只使用自定义参数当然会很容易,但我想使用内置参数以获得更无缝的体验。如何跟踪-q--quiet

【问题讨论】:

    标签: java maven command-line-interface pom.xml


    【解决方案1】:

    您可以查看exec-maven-plugin - list 的可选参数列表

    对于--quite,只需添加到插件配置中

    <quietLogs>true</quietLogs>
    

    【讨论】:

    • 我知道我可以添加这个,但我只想在 -q 标志打开的情况下添加它——那么我如何检查 pom 中是否打开?
    • 我现在明白你的意思了。但不确定 maven 是否允许传播这些 cmd 行选项以供自定义使用。一种使用不同配置文件的选项。
    猜你喜欢
    • 1970-01-01
    • 2013-01-13
    • 2018-10-08
    • 2012-11-30
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 2014-08-03
    • 2013-11-12
    相关资源
    最近更新 更多