user63898
user63898

Reputation: 30895

How to set property value from outside pom.xml

I like to inject from outside the ${project.version} value, this is example pom.xml:

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <version>2020.cool_app-SNAPSHOT</version>
  

    <properties>
        <foo>myapp:${project.version}</foo>
    </properties>
</project>

I run:

mvn clean install 

to compile, how can I from outside to set the ${project.version} to the new one? As parameter or something?

Upvotes: 0

Views: 590

Answers (1)

Stanislav Bashkyrtsev
Stanislav Bashkyrtsev

Reputation: 15308

The variables are set as mvn install -Dprop=value. Note that there are built-in house-keeping variables like project.version - for them to change you need to actually update the <version> first:

mvn version:set -DnewVersion=1.1.1 clean install

This will update pom.xml files - if you don't need that you'll have to rollback the changes with your VCS commands.

Alternatively you can define a new property that defaults to the built-in value: <v>${project.version}</v>. And then override it:

mvn -Dv=1.1.1 clean install

Upvotes: 2

Related Questions