How to get a command-line property to overwrite a maven property

Put parameters directly to pom from command line for example:

mvn clean install -Dtestng.version=6.3.1

Example:

     <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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.test</groupId>
        <artifactId>test</artifactId>
        <version>1.0.0</version>
        <name>test</name>
        <properties>
                <testng.version>6.4</testng.version>
        </properties>

        <dependencies>
                <dependency>
                        <groupId>org.testng</groupId>
                        <artifactId>testng</artifactId>
                        <version>${testng.version}</version>
                        <scope>test</scope>
                </dependency>
        </dependencies>
</project>

If you run it normally testng version 6.4 will be used. But if you run it like: mvn clean install -Dtestng.version=6.3.1 testng version 6.3.1 will be used.

See Setting Maven params in Jenkins

Leave a Comment

tech