2

Maven properties are sometimes present for interpolation in plugin configurations and sometimes not. Why is this?

For example, in the following fragment, the antrun plugin can access the dependencies property and returns the local path of the jar as expected. The exec plugin fails because the ${...} evaluates to null.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>eg</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.0</version>
    </dependency>
</dependencies>
<build>
    <plugins>

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>process-resources</phase>
                    <configuration>
                        <tasks>
                            <echo>Path in antrun: </echo>
                            <echo>${maven.dependency.commons-io.commons-io.jar.path}</echo>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <phase>process-resources</phase>
                    <configuration>
                        <executable>echo</executable>
                        <arguments>
                            <argument>Path in mvn exec</argument>
                            <argument>${maven.dependency.commons-io.commons-io.jar.path}</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Output:

$ mvn process-resources
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building eg 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ eg ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-antrun-plugin:1.3:run (default) @ eg ---
[INFO] Executing tasks
     [echo] Path in antrun:
     [echo] C:\Users\Jim\.m2\repository\commons-io\commons-io\2.0\commons-io-2.0.jar
[INFO] Executed tasks
[INFO]
[INFO] --- exec-maven-plugin:1.2:exec (default) @ eg ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.288s
[INFO] Finished at: Mon Feb 11 14:24:03 GMT 2013
[INFO] Final Memory: 4M/121M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:exec (default) on project eg: Misconfigured argument, value is null. Set the argument to an empty value if this is the required behaviour. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
Jim Downing
  • 1,481
  • 12
  • 29

1 Answers1

4

The dependency-like property is only available to the maven-antrun-plugin. I don't know if you've had to use Maven dependencies from within an actual Ant script, but if you'd played wth it, you would know that Ant has the:

<artifact:dependencies ...>
    <pom file="mypom.xml"/>
</artifact:dependencies>

Which is basically what let's you work with paths to Maven dependencies.

In your case, I believe this is getting hidden from your plain-sight and you've got the paths to the dependencies as properties. What I'm trying to say is that the plugin is handling this for you itself. Thus, other plugins don't see these properties, as the maven-antrun-plugin isn't exporting actual Maven properties, but rather -- properties within the scope of Ant itself.

I hope that makes more sense.

carlspring
  • 31,231
  • 29
  • 115
  • 197
  • 1
    Thanks, Carl! The corollary question is how you _do_ access these locations. An answer I found that does work is here: http://stackoverflow.com/a/8206943/175469 – Jim Downing Feb 12 '13 at 13:28