tags:

views:

58

answers:

2

I've embedded the following code within my POM:

<plugin name="test">
  <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
      <executions>
        <execution>
          <phase>validate</phase>
            <configuration>
              <tasks>
                <pathconvert targetos="unix" property="project.build.directory.portable">
                  <path location="${project.build.directory}"/>
                </pathconvert>
              </tasks>
            </configuration>
          <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>

I then reference ${project.build.directory.portable} from the run project action but it comes back as null. Executing <echo> within the Ant block shows the correct value. What am I doing wrong?

A: 

I don't think you can set a property from Ant that will be visible from Maven. You should write a Mojo.

Pascal Thivent
Put it another way: how would you ensure that ${basedir} contains unix-style slashes even under Windows?
Gili
@Gili I'm not under Windows so I can't test things extensively (sorry, too lazy to start a VM) but I don't think you can. I still don't get why you need this but if it was the case, I would inject the `basedir` property in a Mojo, rewrite it using unix style slashes and expose it under another property.
Pascal Thivent
@Pascal Sure but that would require me to write a new mojo. Isn't there an elegant way to do this with the existing plugins?
Gili
This doesn't seem to be possible from the Ant plugin :(
Gili
A: 

From the plugin documentation here:

Try to add the maven prefix, so you have <path location="${maven.project.build.directory}"/> instead

If that doesn't work, you may need to explictly redefine the property yourself:

<property name="maven.project.build.dir" value="${project.build.directory}"/>
<path location="${maven.project.build.directory}"/>
gregcase