Reputation: 2470
How to write (or overwrite) the following contents:
<dependencies>
<dependency>
<groupId>ged.eprom</groupId>
<artifactId>epromx</artifactId>
<version>${version.to.set}</version>
<classifier>stubjava</classifier>
</dependency>
</dependencies>
into file called pom.xml in the current directory.
I have tried the ant script:
<echo file="pom.xml">
<dependencies>
<dependency>
<groupId>ged.eprom</groupId>
<artifactId>epromx</artifactId>
<version>${version.to.set}</version>
<classifier>stubjava</classifier>
</dependency>
</dependencies>
</echo>
But I obtained the error message:
echo doesn't support the nested "dependencies" element.
Upvotes: 4
Views: 11660
Reputation: 4336
You must escape the content with a CDATA tag, that also means that it won't interpret the variable substitution, so I would break it up in three echo statements.
<echo file="pom.xml"><![CDATA[
<dependencies>
<dependency>
<groupId>ged.eprom</groupId>
<artifactId>epromx</artifactId>
<version>]]></echo>
<echo file="pom.xml" append="true">${version.to.set}</echo>
<echo file="pom.xml" append="true"><![CDATA[</version>
<classifier>stubjava</classifier>
</dependency>
</dependencies>
]]> </echo>
Upvotes: 24
Reputation: 23041
You have the echoxml
task:
http://ant.apache.org/manual/Tasks/echoxml.html
<echoxml file="pom.xml">
<dependencies>
<dependency>
<groupId>ged.eprom</groupId>
<artifactId>epromx</artifactId>
<version>${version.to.set}</version>
<classifier>stubjava</classifier>
</dependency>
</dependencies>
</echoxml>
Upvotes: 13
Reputation: 39485
The ant parser is reading the data that you want to echo as an attempt to add invalid child elements to an <echo/>
parent. If you would like to echo that info out to pom.xml
, you should use the <
and >
entities to encode your element output:
<echo file="pom.xml">
<dependencies>
<dependency>
<groupId>ged.eprom</groupId>
<artifactId>epromx</artifactId>
<version>${version.to.set}</version>
<classifier>stubjava</classifier>
</dependency>
</dependencies>
</echo>
Upvotes: 3