How to override maven property in command line?

MavenCommand LineMaven 3

Maven Problem Overview


I have the following plain pom running 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 default settings in command line like this:

mvn -Dproject.build.finalName=build clean package

But this this is ignored, and I get test-1.0.jar. I've tried to change another properties, like outputDirectory, directory, artifactId, but also failed.

What is the proper way to do this thing?

Maven Solutions


Solution 1 - Maven

See Introduction to the POM

finalName is created as:

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

One of the solutions is to add own property:

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

And now try:

mvn -DfinalName=build clean package

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionglaz666View Question on Stackoverflow
Solution 1 - MavenAndrzej JozwikView Answer on Stackoverflow