Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

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

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?

I couldn't find one. Thanks.

question from:https://stackoverflow.com/questions/17332857/how-to-use-the-mvn-d-to-set-multiple-properties-in-maven-via-command-line

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...