|
Generate Adobe AIR versionNumber automatically with Maven
Problem
Since Adobe AIR 3 the AIR Application descriptor needs to include a versionNumber. If you build your Project with my preferred plugin Flex-Mojos and you don't want to add a new property that is ie. called "1.0.4" because you like to use your project.version from maven, you maybe run into a NPE from AIR adt compiler. This is if your project.version (ie. 1.0.49-SNAPSHOT) is not in the only valid format: <0-999>[.<0-999>][.<0-999>]
Solution
A easy way to automatically "generate" a versionNumber from project.version is to use the Groovy Maven Plugin:
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
String airVersion = project.version;
if( airVersion.indexOf('-') != -1 ) {
airVersion = airVersion.substring( 0, airVersion.indexOf('-') );
}
project.properties['profile.AIRApp.version'] = airVersion;
println 'DEBUG: AIR Descriptor versionNumber='+project.properties['profile.AIRApp.version']
</source>
</configuration>
</execution>
</executions>
</plugin>
This way the AIR Application could be compiled with Flex-Mojos without thee need to specify a manual versionNumber Parameter and you still can build SNAPSHOTS. To use the parameter you can use the versionNumber like in the following sample descriptor.
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<application xmlns="http://ns.adobe.com/air/application/3.1">
<id>MyAPP</id>
<filename>MyApp</filename>
<name>MyApp</name>
<versionLabel>${version}</versionLabel>
<versionNumber>${profile.AIRApp.version}</versionNumber>
<initialWindow>
<content>[This value will be overwritten by Flex Builder in the output app.xml]</content>
</initialWindow>
</application>
One more trick is necessary to filter your descriptor file. This could be done like in the following snippet from AIR Modules pom.
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/flex</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.png</exclude>
<exclude>**/*.swf</exclude>
</excludes>
<targetPath>${project.build.directory}/filtered-sources/flex</targetPath>
</resource>
</resources>
<sourceDirectory>${project.build.directory}/filtered-sources/flex</sourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<flexBuilderCompatibility>true</flexBuilderCompatibility>
<sourceFile>MyApp.mxml</sourceFile>
<descriptorTemplate>${project.build.directory}/filtered-sources/flex/MyApp-app.xml</descriptorTemplate>
<keystore>${basedir}/cert.p12</keystore>
<storepass>mypass</storepass>
</configuration>
<executions>
<execution>
<goals>
<goal>sign-air</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
|
|
Einen Kommentar verfassen
|