1

I have a directory structure like the following:

root/ui/
root/ui/pom.xml
root/ui/build.xml
root/ui/_idea/{files that I want copied are here}
root/ui/ssui/pom.xml (An inner module)

In my POM file, I'm trying to call the ant file using

<tasks>
    <ant antfile="build.xml" target="copyIntelliJFiles"/>
</tasks>

And my build.xml contains

<project name="ui-parent" default="copyIntelliJFiles" basedir=".">
    <target name="copyIntelliJFiles">
         <copy todir="." overwrite="true">
            <fileset dir="_idea"/>
        </copy>
    </target>
</project>

However, when I run mvn install from /root/ui, I get the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (create-intellij-project-files) on project ssui-parent: An Ant BuildException has occured: The following error occurred while executing this line: [ERROR] java.io.FileNotFoundException: /root/ui/ssui/build.xml (No such file or directory) [ERROR] -> [Help 1]

It seems to be running it from /root/ui/ssui instead of where the pom.xml is.

Debugging Done

  • If I change my pom.xml to instead point to ../build.xml, the error message becomes: java.io.FileNotFoundException: /root/build.xml (No such file or directory)

  • If I remove the sub-module definition in /root/ui/pom.xml, then the path is recognized correctly (but I need the submodules)

  • If I change the build.xml reference to ${basedir}/build.xml, I get the same error: java.io.FileNotFoundException: /root/ui/ssui/build.xml and it also works if I remove the sub-module

  • Tried the solution at Maven2 property that indicates the parent directory by creating a ui.rootdir property in both ui/pom.xml (as ${basedir}) and in ui/ssui/pom.xml (as ${basedir}/..) and referenced ${ui.rootdir}/build.xml from ui/pom.xml. Same error.

Any suggestions are welcome, but I can't restructure my directories, except for where the folder that is going to be copied lives. I did look at Usage of maven ${basedir} in multi-module setup but didn't figure out how it would solve my problem.

I created a zip file that illustrates the problem. If you run mvn install you'll notice that an error occurs from within the sub module, though it does run fine in the top level module (and copies the file in my folder)

Community
  • 1
  • 1
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217
  • You may just preceed `${basedir}/` before build.xml. More details, please see https://books.sonatype.com/mcookbook/reference/ch04s03.html. Infact, it is working as it ease like what you mentioned. – Rao Dec 23 '15 at 14:35
  • @Rao It's the exact same behavior as without `${basedir}`, I updated the debugging section to contain that information. If I don't have sub-modules, then both ways work. – Ruan Mendes Dec 23 '15 at 14:41
  • Tried exactly as yours, if you want to take a look, please find the tested files here http://s000.tinyupload.com/index.php?file_id=69167289379588586961 and is working fine. – Rao Dec 23 '15 at 14:55
  • @Rao Thanks, but your example doesn't define an inner module. The problem only happens when you have a sub-module. See `If I remove the sub-module definition in /root/ui/pom.xml, then the path is recognized correctly (but I need the submodules)` – Ruan Mendes Dec 23 '15 at 15:14
  • Would you please update my file to reproduce the issue and upload it again? – Rao Dec 23 '15 at 15:16

1 Answers1

0

The following solution did work for me. It is not very likely to apply to others, since it relies on an environment variable (which we already require for our build).

In root/ui/pom.xml, I added

  <properties>
      <ui.basedir>${env.VCLOUD_SRC_ROOT}/ui</ui.basedir>
  </properties>

   ...
   <target>
     <copy todir="${ui.basedir}" overwrite="true">
       <fileset dir="${ui.basedir}/_idea"/>
     </copy>
     <replace file="${ui.basedir}/.idea/libraries/swfaddress_2_3.xml" token="$LOCAL_REPO$" value="${local.repo}" />
   </target>
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217