Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change maven properties using Ant task

I have set a maven property in the pom.xml.

<properties>
    <build.start.date>someValue</build.start.date>
</properties>

Now I have an ant task doing the following:

<loadresource property="build.start">
    <url url="http://someUrl?xpath=/*/id/text()"/>
</loadresource>

<property name="build.start.date" value="${build.start}"/>

<echo>Printing Ant Value ${build.start} </echo>
<echo>Printing Maven Value ${build.start.date}</echo>

This results in:

[echo] Printing Ant Value 2013-03-15_17-53-08
[echo] Printing Maven Value 2013-03-16

But I am expecting both to print:

[echo] Printing Ant Value 2013-03-15_17-53-08
[echo] Printing Maven Value 2013-03-15_17-53-08


I tried <loadresource property="build.start.date">
and
I tried <loadresource property="${build.start.date}">

So the question is how do I set a global maven property inside ant task?

like image 401
Aneesh Vijendran Avatar asked Apr 19 '13 09:04

Aneesh Vijendran


People also ask

Can we use Maven and Ant together?

You can actually wrap an ANT project with Maven by using multiple ant run goals as I wrote in a different question. Assuming your existing ant project has clean and build tasks, this might be a useful way of wrapping the project so you can use maven goals and have it map to existing ant code.

How do I run Ant tasks in Maven?

Run. The maven-antrun-plugin has only one goal, run . This allows Maven to run Ant tasks. To do so, there must be an existing project and maven-antrun-plugin must have its <target> tag configured (although it would still execute without the <target> tag, it would not do anything).

What is Maven Ant Tasks?

The Maven Ant Tasks allow several of Maven's artifact handling features to be used from within an Ant build. These include: Dependency management - including transitive dependencies, scope recognition and SNAPSHOT handling. Artifact deployment - deployment to a Maven repository (file integrated, other with extensions)

What is Maven Antrun plugin used for?

This plugin provides the ability to run Ant tasks from within Maven. You can even embed your Ant scripts in the POM! It is not the intention of this plugin to provide a means of polluting the POM, so it's encouraged to move all your Ant tasks to a build.


1 Answers

I found the solution for this one.

First of all you need to have 1.7 version of antrun plugin:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
....
</plugin>

Then under configuration you need to have exportAntProperties to true (false by default):

<configuration>
<exportAntProperties>true</exportAntProperties>
like image 138
Aneesh Vijendran Avatar answered Oct 10 '22 09:10

Aneesh Vijendran