How to use the mvn -D to set (multiple) properties in Maven via command line?

后端 未结 1 1078
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 13:02

How to use the mvn -D in maven? How to set a property (or multiple properties) using it?

Are there any official articles for mvn -D?

<
相关标签:
1条回答
  • 2020-12-23 13:41

    The proper way to set a property via command-line using -D is:

    mvn -DpropertyName=propertyValue clean package
    
    • If propertyName doesn't exist in the pom.xml, it will be set.
    • If propertyName already exists in the pom.xml, its value will be overwritten by the one passed as argument via -D.

    To send multiple variables, use multiple space delimited -Ds:

    mvn -DpropA=valueA -DpropB=valueB -DpropC=valueC clean package
    

    You can check more details about properties in Maven: The Complete Reference. More specifically, in section: 6.1. Maven Command Line Options/6.1.1. Defining Properties.

    Example:

    If you have in your pom.xml:

    <properties>
        <theme>myDefaultTheme</theme>
    </properties>
    

    Then mvn -Dtheme=halloween clean package would overwrite themes value during this execution, having the effect as if you had:

    <properties>
        <theme>halloween</theme>
    </properties>
    
    0 讨论(0)
提交回复
热议问题