Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant, (over)write into a file

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.
like image 463
pindare Avatar asked Nov 27 '22 23:11

pindare


1 Answers

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>
like image 147
Alexander Kjäll Avatar answered Dec 04 '22 04:12

Alexander Kjäll