Java 在 maven 2 的命令行上设置插件的属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/752724/
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
Set plugin's property on the command line in maven 2
提问by whaley
In maven 2.x, how would one set a plugin's property on the command line instead of in the <configuration> of that plugin in the pom or in settings.xml?
在 maven 2.x 中,如何在命令行而不是在 pom 或 settings.xml 中该插件的 <configuration> 中设置插件的属性?
For example, if I was using mvn dependency:copy-dependencies
(seen here) how can I set the useRepositoryLayout property without touching either the pom or my settings.xml?
例如,如果我正在使用mvn dependency:copy-dependencies
(见此处),如何在不触及 pom 或我的 settings.xml 的情况下设置 useRepositoryLayout 属性?
Thanks!
谢谢!
采纳答案by whaley
Answer was right in front of me in the copy-dependencies mojo docs (I even linked to it). The documentation for the property includes the Expression you can refer to it by.
在 copy-dependencies mojo 文档中,答案就在我面前(我什至链接到它)。该属性的文档包括您可以参考的表达式。
useRepositoryLayout: Place each artifact in the same directory layout as a default repository. example: /outputDirectory/junit/junit/3.8.1/junit-3.8.1.jar
* Type: boolean * Since: 2.0-alpha-2 * Required: No * Expression: ${mdep.useRepositoryLayout} * Default: false
useRepositoryLayout:将每个工件放在与默认存储库相同的目录布局中。示例:/outputDirectory/junit/junit/3.8.1/junit-3.8.1.jar
* Type: boolean * Since: 2.0-alpha-2 * Required: No * Expression: ${mdep.useRepositoryLayout} * Default: false
To set this property from command line you need to run
要从命令行设置此属性,您需要运行
mvn -Dmdep.useRepositoryLayout=true <goals go here>
回答by David Rabinowitz
Usually you set maven properties using the same syntax as java system properties. Have you tried the following line?
通常您使用与 java 系统属性相同的语法设置 maven 属性。您是否尝试过以下行?
mvn -DuseRepositoryLayout=true dependency:copy-dependencies
回答by bcolfer
Define the properties as arbitrary properties ... not the standard maven props such as version. In my case I defined a new property build.version:
将属性定义为任意属性……而不是标准的 Maven 道具,例如 version。就我而言,我定义了一个新属性 build.version:
<properties> build.version=unknown </properties>
I use the property:
我使用该属性:
<warName>${build.version}</warName>
I define the property:
我定义了属性:
mvn -P prod -Dbuild.version=app_name-branch_name-build_number package
回答by Jared
The other answers here were not clear to me. This is the way I understand it:
我不清楚这里的其他答案。这是我理解的方式:
If the plugin code uses a system property for its parameter, then you can define the value on the command line.
如果插件代码为其参数使用系统属性,那么您可以在命令行上定义该值。
There are 3 different ways you can accomplish this in the plugin code:
您可以通过 3 种不同的方式在插件代码中完成此操作:
@parameter expression="${aSystemProperty}"
@parameter default-value="${anExpression}"
@parameter property="aSystemProperty"
If any or a combination of these methods are used in the plugin code for a particular property, then you can specify a value for the plugin parameter, on the command line. Above code was taken from maven docs here.
如果在特定属性的插件代码中使用了这些方法中的任何一个或这些方法的组合,那么您可以在命令行上为插件参数指定一个值。上面的代码取自这里的 maven 文档。
If you are using a plugin with the above code, you could specify a value for your property using the following command:
如果您使用具有上述代码的插件,您可以使用以下命令为您的属性指定一个值:
mvn -DaSystemProperty=my-value <goal-here>