Maven antrun: pass maven properties to ant -


i trying pass maven properties (defined through profiles) antrun execution:

<plugin>     <groupid>org.apache.maven.plugins</groupid>     <artifactid>maven-antrun-plugin</artifactid>     <version>1.7</version>     <dependencies>         <!-- ... these 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 sshexec , 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 defined in profiles allow deployment in different servers (i know it's not best possible approach, way things done here), this:

<profile>     <id>aprofile</id>     <properties>         <property name="serverdeploy" value="somevalue" />         <property name="userdeploy" value="someuser" />         <property name="passworddeploy" value="somepassword" />          <!-- , on -->     </properties> </profile> 

my problem can't maven properties work in ant plugin; tried add <echoproperties> task in ant see properties have , there no trace of maven properties. possible use maven defined properties or should use approach? suggestion welcome.

edit: modified script per first answer, still doesn't work

you can pass properties defining new ant properties (using property tag in target within configuration). 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-module</artifactid>     <name>test-module</name>     <version>snapshot</version>      <properties>         <my.custom.property>false</my.custom.property>     </properties>      <profiles>         <profile>             <id>customprofile</id>             <properties>                 <my.custom.property>true</my.custom.property>             </properties>         </profile>     </profiles>      <build>         <plugins>             <plugin>                 <groupid>org.apache.maven.plugins</groupid>                 <artifactid>maven-antrun-plugin</artifactid>                 <version>1.7</version>                 <executions>                     <execution>                         <id>compile</id>                         <phase>compile</phase>                         <configuration>                             <target>                                 <property name="antproperty" value="${my.custom.property}"/>                                 <echo message="custom ant property is: ${antproperty}"/>                                 <echoproperties />                             </target>                         </configuration>                         <goals>                             <goal>run</goal>                         </goals>                     </execution>                 </executions>             </plugin>         </plugins>     </build> </project> 

when execute mvn compile on pom output is:

main: [echo] custom ant property is: false [echoproperties] #ant properties [echoproperties] #thu aug 08 17:17:30 cest 2013 [echoproperties] ant.project.name=maven-antrun- [echoproperties] ant.version=apache ant(tm) version 1.8.2 compiled on december 20 2010 [echoproperties] antproperty=false 

and when command mvn -pcustomprofile compile output is:

main: [echo] custom ant property is: true [echoproperties] #ant properties [echoproperties] #thu aug 08 17:18:30 cest 2013 [echoproperties] ant.project.name=maven-antrun- [echoproperties] ant.version=apache ant(tm) version 1.8.2 compiled on december 20 2010 [echoproperties] antproperty=true 

this works using maven 3.0.5.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -