Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override maven property in command line?

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?

like image 506
glaz666 Avatar asked Dec 14 '12 09:12

glaz666


People also ask

How do I pass system properties to maven?

To provide System Properties to the tests from command line, you just need to configure maven surefire plugin and use -D{systemproperty}={propertyvalue} parameter in commandline. Run Single Test with Maven : $ mvn test -Dtest=MessageUtilTest#msg_add_test -Dmy_message="Hello, Developer!"

How do I pass a command line argument in maven?

Passing an Argument to MavenMaven will use the value (2.5) passed as an argument to replace the COMMON_VERSION_CMD property set in our pom. xml. This is not limited to the package command — we can pass arguments together with any Maven command, such as install, test, or build.

How use mvn command line?

To build a Maven project via the command line, you use the mvn command from the command line. The command must be executed in the directory which contains the relevant pom file. You pass the build life cycle, phase or goal as parameter to this command.

What is mvn clean command?

mvn clean: Cleans the project and removes all files generated by the previous build. mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code.


1 Answers

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

like image 115
Andrzej Jozwik Avatar answered Oct 08 '22 23:10

Andrzej Jozwik