Set plugin's property on the command line in maven 2

后端 未结 4 1258
伪装坚强ぢ
伪装坚强ぢ 2021-02-06 23:28

In maven 2.x, how would one set a plugin\'s property on the command line instead of in the of that plugin in the pom or in settings.xml?

For exampl

相关标签:
4条回答
  • 2021-02-06 23:48

    Usually you set maven properties using the same syntax as java system properties. Have you tried the following line?

    mvn -DuseRepositoryLayout=true dependency:copy-dependencies
    
    0 讨论(0)
  • 2021-02-06 23:52

    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.

    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
    

    To set this property from command line you need to run

    mvn -Dmdep.useRepositoryLayout=true <goals go here>
    
    0 讨论(0)
  • 2021-02-07 00:06

    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:

    @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.

    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>
    
    0 讨论(0)
  • 2021-02-07 00:11

    Define the properties as arbitrary properties ... not the standard maven props such as version. In my case I defined a new property 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
    
    0 讨论(0)
提交回复
热议问题