How to override the maven property on the command line?

I have the following simple pom launched by Maven 3.0.4.

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>test</artifactId> <version>1.0</version> <packaging>jar</packaging> </project> 

I am trying to override the default settings on the command line as follows:

 mvn -Dproject.build.finalName=build clean package 

But this is ignored, and I get test-1.0.jar . I tried to change other properties such as outputDirectory, directory, artifactId, but also failed.

What is the right way to do this?

+44
command-line maven maven-3
Dec 14
source share
1 answer

See Introduction to POM

finalName is created as:

 <build> <finalName>${project.artifactId}-${project.version}</finalName> </build> 

One solution is to add your own property:

 <properties> <finalName>${project.artifactId}-${project.version}</finalName> </properties> <build> <finalName>${finalName}</finalName> </build> 

And now try:

mvn -DfinalName=build clean package

+83
Dec 14 '12 at 11:38
source share



All Articles