I am trying to pass maven properties (defined through profiles) to a antrun execution:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<dependencies>
<!-- ... these are ok -->
</dependencies>
<executions>
<execution>
<configuration>
<target>
<property name="ant_destDir" value="${destDir}" />
<property name="ant_serverDeploy" value="${serverDeploy}" />
<property name="ant_deployDir" value="${deployDir}" />
<property name="ant_userDeploy" value="${userDeploy}" />
<property name="ant_passwordDeploy" value="${passwordDeploy}" />
<!-- correct task definitions for sshexec and scp -->
<sshexec host="${serverDeploy}" username="${userDeploy}"
password="${passwordDeploy}" trust="yes"
command="some command" />
<scp remoteTodir="${userDeploy}@${serverDeploy}:${destDir}"
password="${passwordDeploy}" trust="yes" sftp="true">
<fileset dir="${deployDir}" includes="*.jar" />
</scp>
<sshexec host="${serverDeploy}" username="${userDeploy}"
password="${passwordDeploy}" trust="yes"
command="some command" />
</target>
</configuration>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The properties are defined in profiles to allow for deployment in different servers (I know it's not the best possible approach, but this is the way things are done here), like this:
<profile>
<id>aprofile</id>
<properties>
<property name="serverDeploy" value="somevalue" />
<property name="userDeploy" value="someuser" />
<property name="passwordDeploy" value="somepassword" />
<!-- and so on -->
</properties>
</profile>
My problem is that I can't get maven properties to work in ant plugin; I tried to add a <echoproperties>
task in ant to see which properties I have and there is no trace of maven properties.
Is it possible to use maven defined properties or should I use another approach? Any suggestion is welcome.
Edit: I modified the script as per first answer, it still doesn't work
Most properties are automatically passed along to ant, at least if you're running an inlined ant script. Some of the properties get renamed. I suggest running "mvn -X" and the antrun plugin prints a list of all the variable mappings into ant (things like basedir becomes project.basedir, etc.)
On the newer versions of maven you can just use:
example:
You can pass the properties by defining new Ant properties (using the
property
tag in yourtarget
within theconfiguration
). So for example:When I execute
mvn compile
on this pom the output is:and when the command is
mvn -PcustomProfile compile
then the output is:This works using maven 3.0.5.