java 如何在一个 Maven 命令中执行多个目标,但每个目标都有不同的参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29382952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 15:09:25  来源:igfitidea点击:

How to execute multiple goals in one maven command, but with different arguments for each goal

javamaven

提问by Eric

I am trying to run 2 maven goals in one maven command like:

我正在尝试在一个 maven 命令中运行 2 个 maven 目标,例如:

mvn release:prepare release:perform -Darguments='-Dmaven.test.skip=true'

but, I would like the first goal to skip tests and the second one not to skip tests.

但是,我希望第一个目标跳过测试,第二个目标不要跳过测试。

It has to be in one line command.

它必须在一行命令中。

Is there a way to do it other than executing them in 2 separate commands?

除了在 2 个单独的命令中执行它们之外,还有其他方法吗?

回答by khmarbaise

You can use the following:

您可以使用以下内容:

mvn -Dmaven.test.skip=true release:prepare release:perform

Within release-plugin the arguments are passed via -Darguments='....'to the sub process which is started by release:perform. The other arguments are passed to the process which is started by release:prepare.

在 release-plugin 中,参数-Darguments='....'通过release:perform. 其他参数传递给由 启动的进程release:prepare

回答by Remy

I have spent hours on this.

我在这上面花了几个小时。

My working release command is:

我的工作发布命令是:

-Darguments='-DskipTests=true' -DskipTests release:prepare release:perform

The problem actually was in my release plugin:

问题实际上出在我的发布插件中:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <configuration>
                <arguments>${release.arguments}</arguments>

The "arguments" parameter of the release plugin was overriding the -Darguments that I pass to the release:prepare (in order to be passed to release:perform by release:prepare).

发布插件的“参数”参数覆盖了我传递给 release:prepare 的 -Darguments(为了通过 release:prepare 传递给 release:perform)。