• Maven 2 Property References

    I finally figured out how Maven 2 property references work today. I’m sure this is covered in the documentation somewhere, but since I just sort of jumped in head first I’ve been discovering a lot about Maven through trial and error (and looking at other people’s build scripts).

    For the Flex build script I’ve been working on, I’m using the maven-antrun-plugin to run an Ant task that will run FlexUnit during the test phase of the build. I’m building the SWF in to the standard build area for Maven (the “target” directory) and wanted to reference this in the embedded Ant build. Here’s the POM file that I’m using so far for reference.

    <?xml version="1.0" encoding="UTF-8"?><project> <modelVersion>4.0.0</modelVersion> <groupId>net.israfil.examples</groupId> <artifactId>israfil-swf-example</artifactId> <version>1.0-SNAPSHOT</version> <packaging>swf</packaging> <properties>  <flex.home>/opt/flex_sdk_2</flex.home> </properties> <build>  <finalName>UserManager</finalName>  <plugins>   <plugin>    <groupId>net.israfil.mojo</groupId>    <artifactId>maven-flex2-plugin</artifactId>    <version>1.2-SNAPSHOT</version>    <extensions>true</extensions>    <configuration>     <flexHome>${flex.home}</flexHome>     <useNetwork>true</useNetwork>     <strict>true</strict>     <warning>true</warning>     <main>Test.mxml</main>    </configuration>   </plugin>   <plugin>    <artifactId>maven-antrun-plugin</artifactId>    <executions>     <execution>      <phase>test</phase>      <configuration>       <tasks>        <taskdef         resource="com/adobe/ac/ant/tasks/tasks.properties"         classpathref="maven.compile.classpath" />        <echo message="${project.build.outputDirectory}" />        <echo message="${project.build.finalName}" />        <flexunit timeout="0"         swf="${project.build.directory}/UserManager.swf"         toDir="${project.build.directory}/reports" haltonfailure="true" />       </tasks>      </configuration>      <goals>       <goal>run</goal>      </goals>     </execution>    </executions>   </plugin>  </plugins> </build> <dependencies>  <!-- Add other SWC dependencies for JUnit-style test with output -->  <dependency>   <groupId>actionscript3.flexunit</groupId>   <artifactId>flexunit</artifactId>   <version>0.85</version>   <type>swc</type>  </dependency>  <dependency>   <groupId>com.adobe.ac.ant.tasks</groupId>   <artifactId>flexunitant</artifactId>   <version>1.0</version>  </dependency>  <!-- Required by the FlexUnit Ant Task -->  <dependency>   <groupId>org.dom4j</groupId>   <artifactId>dom4j</artifactId>   <version>1.6.1</version>  </dependency>  <dependency>   <groupId>org.jaxen</groupId>   <artifactId>jaxen</artifactId>   <version>1.1-beta-6</version>  </dependency> </dependencies></project>

    I couldn’t figure out how to reference the Maven property for the project build directory, and searching the web for “maven properties” just came up with the properties from the Maven 1 implementation which didn’t help.

    Then, it hit me: the properties are just dot-notation references for the path to the items in the POM. Taking a look at the Super POM, you can see that the tags wrapping the project build directory (target) are accessible through descendant dot notation.

    So, the following XML snippet from the Super POM:

    <project>  ...  <build>    <directory>target</directory>    <outputDirectory>target/classes</outputDirectory>    <finalName>${pom.artifactId}-${pom.version}</finalName>  ...  </build>  ...</project>

    … would enable you to reference the build directory as ${project.build.directory} (”target”), ${project.build.outputDirectory} (”target/classes”), and ${project.build.finalName} (holding the output of the referenced values “${pom.artifactId}-${pom.version}”).

    I’m sure this is something stupid that anybody familiar with Maven would know, but since it took me a while to figure it out I thought I’d share with the world.

    Category: Uncategorized | Tags: