views:

28

answers:

1

I am running a Maven (2) release build with with: mvn -f release.xml clean deploy and want to get the currently running pom file name (release.xml) into a property or mojo.

Is it possible?

A: 

well you can use the property

${env.MAVEN_CMD_LINE_ARGS}

in your pom or a filtered resource, which will expand to something like

clean install -Paxis -Dmaven.test.skip -f mypom.xml -pl util

however, if you just want the mypom.xml part, you're going to have to do some scripting, which is not supported out of the box in maven. Common solutions are either maven antrun plugin or gmaven (groovy) plugin. Here's a way to do it in gmaven:

<plugin>
    <groupId>org.codehaus.groovy.maven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <executions>
        <execution>
        <phase>process-classes</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <source>
                System.out.println(
                        System
                        .getenv("MAVEN_CMD_LINE_ARGS")
                        .replaceFirst( /.*\-f\s+(\S+).*/ , 'POM File: $1')
                    );
                </source>
            </configuration>
        </execution>
    </executions>
</plugin>

Edit: as you want it in a property, either use System.setProperty or write directly to project.properties

seanizer