The Blog

Sep 29, 2007

Maven 2 Property References 

by Maxim Porges @ 10:48 AM | Link | Feedback (6)

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"?>
classpathref="maven.compile.classpath" />
<echo message="${}" />
<echo message="${}" />
<flexunit timeout="0"
toDir="${}/reports" haltonfailure="true" />
<!-- Add other SWC dependencies for JUnit-style test with output -->
<!-- Required by the FlexUnit Ant Task -->

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:

... would enable you to reference the build directory as ${} ("target"), ${} ("target/classes"), and ${} (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.