javaeclipsemavenant

How to set the parent directory of the basedir in maven as the basedir of ant?


Background : I need to run an ant task in the build.xml file using maven. So I'm using maven-antrun-plugin to do this.

Question :
When I'm reading the basedir in ant (after running pom) it displays as fldr1.fldr2.prjctNm which was it's defualt value (in both echoes). But, I want to set the parent directory path to it. (eg : fldr1.fldr2). How can I do this.

Ant file alone does this because it defines basedir="../ in the tag.

pom.xml (location : fldr1.fldr2.prjctNm)

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>

            <executions>
                <execution>
                    <id>default-cli</id>
                    <phase>package</phase>

                    <configuration>
                        <target>
                            <property name="basedir" value="../" />
                            <echo message="basedir path 1 : ${basedir}"/>
                            <ant antfile="build.xml" target="cleanAll" />
                        </target>
                    </configuration>

                    <goals>
                        <goal>run</goal>
                    </goals>

                </execution>
            </executions>

        </plugin>
    </plugins>
</build>

build.xml (location : fldr1.fldr2.prjctNm)

<project name="RideUtilities" default="cleanAll" basedir="../">

    <target name="cleanAll" depends="all"></target>

    <target name="all" depends="init,build"></target>

    <target name="init">

        <echo message="basedir path 2 : ${basedir}"/>

        <property name="dirs.base" value="${basedir}/RideUtilities" />
        <property name="src" value="${dirs.base}\src" />
        <property name="jarFile" value="RideUtilities.jar" />
    </target>

    <target name="build">
        <echo> ---Building jar files using ${dirs.base} ---- </echo>
    </target>

</project>

Solution

  • I'm not sure there was enough detail about what exactly you needed, but I was able to get the behavior you wanted with basedir as follows:

    pom.xml

    <target>
       <echo message="basedir path 1 : ${basedir}" />
       <ant antfile="build.xml" target="echo-base-dir" inheritAll="false" />
    </target>
    

    build.xml

    <project name="test" basedir="..">
        <target name="echo-base-dir">
            <echo>base dir=${basedir}</echo>
        </target>
    </project>
    

    The output was:

    C:\dev\JavaTests>mvn antrun:run [INFO] Scanning for projects... 
    [INFO]
    [INFO]
    [INFO] Building test Strategy 3.0.7-SNAPSHOT 
    [INFO]
    [INFO] 
    [INFO] --- maven-antrun-plugin:1.7:run (default-cli) @ test-test ---
    [INFO] Executing tasks
    
    main:
         [echo] basedir path 1 : C:\dev\JavaTests
    
    echo-base-dir:
         [echo] base dir=C:\dev
    
    [INFO] Executed tasks
    [INFO]  
    [INFO] BUILD SUCCESS
    [INFO]
    
    [INFO] Total time: 1.005s 
    [INFO] Finished at: Wed Nov 06 09:59:36 EST 2013 
    [INFO] Final Memory: 8M/182M 
    
    C:\dev\JavaTests>
    

    The key was obviously the inheritAll=false. But maybe that will mess up your need to reference some of the Maven properties.