Hi,

I'm trying to use the ant replace task to set a version number in my source
code (yes, I know it should probably be in a properties file, but for
various reasons this is what I'm stuck with).  I want to set the version
number just before the code is compiled, then revert it back to an empty
string after compilation so that the source code remains unchanged for
future builds.

My problem is that the first replace appears to happen correctly, but the
second doesn't.  I believe the tokens to be searched for are correct (I've
just swapped value & token attributes from the first replace), and I've
tried running the replaces independently by commenting out the other and
building.  When I run them individually they work correctly, but together
they do not.

Could there be an issue with the write from the first replace not being
flushed to disk until after the second?

Here's the relevant parts of my pom.xml:

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>set-version-in-java-file</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <tasks>
                                <echo message="Setting product version in
source code" />
                                <replace

file="${basedir}/src/java/.../SysInfo.java"
                                    value="APPLICATION_VERSION =
&quot;${project.version}&quot;;"
                                    token="APPLICATION_VERSION =
&quot;&quot;;" />
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>revert-version-in-java-file</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <tasks>
                                <echo message="Removing product version from
source code" />
                                <replace

file="${basedir}/src/java/.../SysInfo.java"
                                    token="APPLICATION_VERSION =
&quot;${project.version}&quot;;"
                                    value="APPLICATION_VERSION =
&quot;&quot;;" />
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


Any help would be greatly appreciated.

Dave

Reply via email to