【问题标题】:Running ant from a maven module containing other modules从包含其他模块的 maven 模块运行 ant
【发布时间】:2016-03-29 23:03:03
【问题描述】:

我的目录结构如下:

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)

在我的 POM 文件中,我尝试使用

调用 ant 文件
<tasks>
    <ant antfile="build.xml" target="copyIntelliJFiles"/>
</tasks>

我的 build.xml 包含

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

但是,当我从 /root/ui 运行 mvn install 时,出现以下错误:

[错误] 无法在项目 ssui-parent 上执行目标 org.apache.maven.plugins:maven-antrun-plugin:1.6:run (create-intellij-project-files):发生 Ant BuildException:以下执行此行时发生错误: [错误] java.io.FileNotFoundException:/root/ui/ssui/build.xml(没有这样的文件或目录) [错误] -> [帮助 1]

它似乎是从/root/ui/ssui 而不是pom.xml 所在的位置运行它。

调试完成

  • 如果我将 pom.xml 更改为指向 ../build.xml,则错误消息变为:java.io.FileNotFoundException: /root/build.xml (No such file or directory)

  • 如果我删除/root/ui/pom.xml 中的子模块定义,则路径被正确识别(但我需要子模块)

  • 如果我将 build.xml 引用更改为 ${basedir}/build.xml,我会收到相同的错误:java.io.FileNotFoundException: /root/ui/ssui/build.xml,如果我删除子模块,它也可以工作

  • 通过在ui/pom.xml(如${basedir})和ui/ssui/pom.xml(如${basedir}/..)中创建ui.rootdir 属性来尝试Maven2 property that indicates the parent directory 的解决方案,并从@987654345 引用${ui.rootdir}/build.xml @。同样的错误。

欢迎提出任何建议,但我无法重组我的目录,除非要复制的文件夹所在的位置。我确实看过Usage of maven ${basedir} in multi-module setup,但没有弄清楚它如何解决我的问题。

created a zip file 说明了这个问题。如果您运行mvn install,您会注意到子模块中发生错误,尽管它在顶级模块中运行良好(并将文件复制到我的文件夹中)

【问题讨论】:

  • 你可以在 build.xml 之前使用${basedir}/。更多详情请见books.sonatype.com/mcookbook/reference/ch04s03.html。事实上,它就像你提到的那样轻松工作。
  • @Rao 这与没有${basedir} 的行为完全相同,我更新了调试部分以包含该信息。如果我没有子模块,那么两种方式都可以。
  • 和你的一样试过,如果你想看看,请在这里s000.tinyupload.com/index.php?file_id=69167289379588586961找到测试过的文件,并且工作正常。
  • @Rao 谢谢,但您的示例没有定义内部模块。只有当您有子模块时才会出现问题。见If I remove the sub-module definition in /root/ui/pom.xml, then the path is recognized correctly (but I need the submodules)
  • 能否更新我的文件以重现问题并再次上传?

标签: ant maven-3 maven-module


【解决方案1】:

以下解决方案确实对我有用。它不太可能适用于其他人,因为它依赖于环境变量(我们在构建中已经需要它)。

root/ui/pom.xml,我添加了

  <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>

【讨论】:

  • 您可以将 元素替换为 &lt;tasks&gt; &lt;subant target="sample"&gt; &lt;property name="basedir" value="${project.basedir}"/&gt; &lt;fileset dir="${project.basedir}" includes="build.xml"/&gt; &lt;/subant&gt; &lt;/tasks&gt;
猜你喜欢
  • 1970-01-01
  • 2012-04-12
  • 2023-03-28
  • 2011-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-06
  • 2017-10-05
相关资源
最近更新 更多