Tuesday, November 15, 2011

Automatically updating appengine-web.xml's version

If you're using AppEngine in Java land, you're probably using maven with maven-gae-plugin. If you're not, why aren't you?

Anyway, since you already have a project version, why not leverage that in appengine-web.xml's version tag?

<build>
  <plugins>
   <finalName>${project.artifactId}</finalName>
   <!-- Sets the version in appengine-web.xml -->
    <plugin>
      <groupId>com.google.code.maven-replacer-plugin</groupId>
      <artifactId>maven-replacer-plugin</artifactId>
      <version>1.3.9</version>
      <executions>
          <execution>
        <phase>package</phase>
        <goals>
            <goal>replace</goal>
        </goals>
          </execution>
      </executions>
      <configuration>
          <file>target/${project.artifactId}/WEB-INF/appengine-web.xml</file>
          <replacements>
        <replacement>
            <token>%%VERSION%%</token>
            <value>${project.version}</value>
        </replacement>         
          </replacements>
      </configuration>
    </plugin>
  </plugins>
</build>

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  ...
  <version>%%VERSION%%</version>
  ...
</appengine-web-app>

And that's it. When you execute gae:run, gae:deploy, etc, the version will be set automatically.

No comments: