蚂蚁大项目。如何强制执行通用输出目录结构 - include、import 和 inhertAll=false?

发布于 2024-10-18 07:01:43 字数 3171 浏览 6 评论 0原文

我有一个顶级的ant项目和它下面的许多子项目。

./build.xml
./datamodel_src/src/build.xml
./datamodel_src/src/module1/build.xml
./datamodel_src/src/module2/build.xml
./infrastructure_src/src/build.xml
./interfaces_src/src/build.xml

我想在每个子项目中强制执行一个通用的输出目录结构。项目将有一个工作区,每个子项目下都有自己的工作区。每个子项目都应该在子项目的工作区下创建其工件(库、文档、类等)。

所以输出会类似于

c:/sandbox/mainprojectworkarea/subprojectworkarea/lib
c:/sandbox/mainprojectworkarea/subprojectworkarea/docs
c:/sandbox/mainprojectworkarea/subprojectworkarea/classes

“当前我这样做”,如下所示。

顶层 build.xml 如下所示

<project name="toplevelproject" default="compile" basedir=".">
    <target name="compile">
        <ant dir="infrastructure_src/src" />
        <ant dir="interfaces_src/src " /> <!--does not work-->
        <ant dir="datamodel_src/src inhertAll=false" /> <!--works-->
    </target>
</project>

common.xml 如下所示

<property environment="env" />
<property name="project.sandbox" value="${env.BUILD_HOME}/sandbox" />
<property name="sandbox"  value="${project.sandbox}" />
<property name="pwa"  value="${sandbox}/pwa" />
<property name="wa"  value="${pwa}/${ant.project.name}" />
<property name="build"  value="${wa}/build" />
<property name="lib"  value="${wa}/lib" />
<property name="docs"  value="${wa}/docs" />
<property name="exports"  value="${wa}/exports" />

这是“包含”到所有项目中的。例如,“datamodel_src/src/build.xml”如下所示,

<!DOCTYPE project [
       <!ENTITY common SYSTEM "../../common.xml">
]>

<project name="dmodel" default="compile" basedir=".">
    &common;
    <target name="compile">
        <echo  message="will create lib  in  ${lib}"/>
        <echo  message="will create docs  in  ${docs}"/>
        <ant dir="module1" inheritAll="false"/> <!--works fine-->
        <ant dir="module2" /> <!--does not work -->
    </target>   
</project>

当我为 ant 调用设置 inhertiAll=false 时,这会起作用。

有没有更好、正确的方法呢?

扩展凯文对这个问题的回答。 使用 import common.xml 成为一个真实的项目,如下所示。

<project name="toplevelproject" default="compile" basedir=".">
    <property name="toplevel" value="settotrue"/>
    <target name="compile">
        <ant dir="infrastructure_src/src" />
        <ant dir="interfaces_src/src" />
        <ant dir="datamodel_src/src" />
    </target>
</project>

“datamodel_src/src/build.xml”现在有些人的想法如下。

<project name="dmodel" default="compile" basedir=".">
    <import file="../../common.xml" />
    <target name="compile">
        <echo  message="will create classes in  ${build}"/>
        <echo  message="will create lib  in  ${lib}"/>
        <ant dir="module1" inheritAll="false"/> <!--works fine-->
        <ant dir="module2" /> <!--does not work -->
    </target>
</project>

导入提供了具有共同目标等的选项,因此我会选择它。

I have a toplevel ant project and many subprojects under it.

./build.xml
./datamodel_src/src/build.xml
./datamodel_src/src/module1/build.xml
./datamodel_src/src/module2/build.xml
./infrastructure_src/src/build.xml
./interfaces_src/src/build.xml

Each of the subproject, I want to enforce a common output directory structure. Project will have a work area and each sub project will have its own work area under it. Each subproject should create its artifacts (lib, docs, classes etc) under a work area for the subproject.

So the output would be some thing like

c:/sandbox/mainprojectworkarea/subprojectworkarea/lib
c:/sandbox/mainprojectworkarea/subprojectworkarea/docs
c:/sandbox/mainprojectworkarea/subprojectworkarea/classes

Currently I do this as follows.

The toplevel build.xml is like below

<project name="toplevelproject" default="compile" basedir=".">
    <target name="compile">
        <ant dir="infrastructure_src/src" />
        <ant dir="interfaces_src/src " /> <!--does not work-->
        <ant dir="datamodel_src/src inhertAll=false" /> <!--works-->
    </target>
</project>

common.xml is like below

<property environment="env" />
<property name="project.sandbox" value="${env.BUILD_HOME}/sandbox" />
<property name="sandbox"  value="${project.sandbox}" />
<property name="pwa"  value="${sandbox}/pwa" />
<property name="wa"  value="${pwa}/${ant.project.name}" />
<property name="build"  value="${wa}/build" />
<property name="lib"  value="${wa}/lib" />
<property name="docs"  value="${wa}/docs" />
<property name="exports"  value="${wa}/exports" />

This is "included" into all projects. For example "datamodel_src/src/build.xml" is like below

<!DOCTYPE project [
       <!ENTITY common SYSTEM "../../common.xml">
]>

<project name="dmodel" default="compile" basedir=".">
    &common;
    <target name="compile">
        <echo  message="will create lib  in  ${lib}"/>
        <echo  message="will create docs  in  ${docs}"/>
        <ant dir="module1" inheritAll="false"/> <!--works fine-->
        <ant dir="module2" /> <!--does not work -->
    </target>   
</project>

This works when I set inhertiAll=false for ant calls.

Is there a better and correct way to?

Expanding answer from Kevin to this question.
Using import the common.xml becomes a real project like below

<project name="toplevelproject" default="compile" basedir=".">
    <property name="toplevel" value="settotrue"/>
    <target name="compile">
        <ant dir="infrastructure_src/src" />
        <ant dir="interfaces_src/src" />
        <ant dir="datamodel_src/src" />
    </target>
</project>

The "datamodel_src/src/build.xml" is now some think like below.

<project name="dmodel" default="compile" basedir=".">
    <import file="../../common.xml" />
    <target name="compile">
        <echo  message="will create classes in  ${build}"/>
        <echo  message="will create lib  in  ${lib}"/>
        <ant dir="module1" inheritAll="false"/> <!--works fine-->
        <ant dir="module2" /> <!--does not work -->
    </target>
</project>

The import gives option to have common targets etc, hence I would go with it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阿楠 2024-10-25 07:01:43

我正在使用 导入 而不是包含做类似的事情。我所有的公共目标和属性都在公共构建文件中定义,每个子项目仅导入公共文件。导入文件时,该文件中定义的属性将与导入文件相关。

因此,我会尝试执行以下操作:

  1. 将编译目标从子项目构建文件移至 common.xml。

  2. 将 common.xml 导入到每个子项目 build.xml 中。

I'm doing something similar using imports rather than includes. All my common targets and properties are defined in a common build file and each subproject just imports the common file. When you import a file, the properties defined in that file become relative to the importing file.

So I would try doing the following:

  1. Move your compile target from your subproject build files into your common.xml.

  2. Import your common.xml into each subproject build.xml.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文