I think you did not use the correct solution.
The Maven recommended way is to use a property file which will be loaded by
your Java file(as a resource bundle for example) to get the version string.
The property file should be stored in src/main/resources and will be
automatically processed by Maven using the filtering option of Maven. This
will prevents unnecessary Ant files to do the job.

Regards
Jeff MAURY

On Fri, Jan 16, 2009 at 2:38 PM, David Moss <[email protected]> wrote:

> 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
>



-- 
La mélancolie c'est communiste
Tout le monde y a droit de temps en temps
La mélancolie n'est pas capitaliste
C'est même gratuit pour les perdants
La mélancolie c'est pacifiste
On ne lui rentre jamais dedans
La mélancolie oh tu sais ça existe
Elle se prend même avec des gants
La mélancolie c'est pour les syndicalistes
Il faut juste sa carte de permanent

Miossec (2006)

http://www.jeffmaury.com
http://riadiscuss.jeffmaury.com
http://www.lastfm.fr/listen/user/jeffmaury/personal
Mes CDs à récupérer:
http://spreadsheets.google.com/ccc?key=pNeg4Doa_oCsh7CepKPaPTA&hl=en

Reply via email to