To overwrite a property defined in the POM use the parâmetro -D
typical of any Java application when invoking the mvn
For example to deploy assets shared by applications to a TEST directory :
mvn -P deployShared package -Dshared_dir=/usr/local/Cellar/tomcat/7.0.47/shared
In this example we are overwriting shared_dir during the package phase. This variable is used by the deployShared profile defined in the POM to copy the files to the Tomcat environment (version 7.0.47) used for Testing.
The same POM can be used to deploy to the Homologation as follows:
mvn -P deployShared package -Dshared_dir=/usr/local/tomcat-7.0.47-homolog/shared
And so on and so forth.
The profile deployShared
uses the maven-dependency-plugin
and would look like this:
<profile>
<id>deployShared</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${shared_dir}</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<outputDirectory>${shared_dir}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</profile>
hi @Joao-Parana I am not required to use Profile in POM, right ? In case I use as it would in this your example ?
– bmkrio
I edited the answer and put up the profile. It is not necessary to use profile but in a group work can help in factorizing the Build via Maven configuration files (POM parent, POM child, Settings.xml, etc)
– João Paraná