ant构建脚本问题

发布于 2024-11-01 05:26:59 字数 3280 浏览 2 评论 0原文

我有 2 个名为“build”和“tarne”的 ant 构建脚本

Build:

<?xml version="1.0" ?>
<project name="build" default="zip">

    <property name="project.name" value="projectName"/>
    <property name="version" value="default_version_value"/>


    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="lib/build/ant-contrib.jar"/>
        </classpath>
    </taskdef>  

    <var name="version2" value="default_version_value"/>


    <property name="tmp" value="tmp"/>  
    <property name="build.dir" location="${tmp}/component/${project.name}"/>
    <property name="java.classes" location="${tmp}/component/${project.name}/classes"/>
    <property name="weblayout.dir" location="${tmp}/weblayout/resources/${project.name}"/>


    <path id="compile.classpath">
        <fileset dir="lib" includes="**/*.jar" />
        <fileset dir="lib/build" includes="*.zip" />
    </path>

    <target name="clean">
        <delete dir="${tmp}" />
    </target>

    <target name="init" depends="clean">
        <mkdir dir="${java.classes}" />
    </target>

    <target name="compile" depends="init">
        <javac srcdir="src" source="1.5" target="1.5" encoding="utf-8" includes="**/*.java" destdir="${java.classes}" classpathref="compile.classpath" />
    </target>

    <target name="copy-resources" depends="compile">

            //Lots of copying here

    </target>

    <target name="read.version" description="Parses the hda file for your version number">

        <property file="${project.name}.hda" prefix="hda"/>
        <propertyregex property="version" input="${hda.version}" regexp="\." replace="-" global="true" override="true"/>
        <var name="version2" value="${version}"/>

        <echo>${version}</echo>
        <echo>${version2}</echo>


    </target>

    <target name="zip" depends="copy-resources, read.version" description="Package component">

        <zip destfile="${project.name}-${version}.zip" basedir="${tmp}" />
        <delete dir="${tmp}" />

    </target>


</project>

Tarne:

<?xml version="1.0" ?>
<project default="tarne">

    <include file="build.xml"/>
    <property name="project.name" value="build.project.name"/>

    <target name="tarne">

        <antcall target="build.read.version" inheritRefs="true"></antcall>
        <property name="version" value="build.version"/>
        <property name="version2" value="build.version2"/>

        <echo>${version}</echo> 
        <echo>${version2}</echo>    



    </target>

</project>

当我运行 tarne.xml 时得到的输出是:

Buildfile: tarne.xml
tarne:
build.read.version:
     [echo] v1-0-1
     [echo] v1-0-1
     [echo] default_version_value
     [echo] default_version_value

其中前 2 行 (v1-0-1) 来自 read.version 内部build.xml 的目标和接下来的两行来自 tarne.xml。总体想法是我应该能够访问 tarne.xml 构建脚本中的版本号。

关于出了什么问题有什么想法吗?

I have 2 ant build scripts named "build" and "tarne"

Build:

<?xml version="1.0" ?>
<project name="build" default="zip">

    <property name="project.name" value="projectName"/>
    <property name="version" value="default_version_value"/>


    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="lib/build/ant-contrib.jar"/>
        </classpath>
    </taskdef>  

    <var name="version2" value="default_version_value"/>


    <property name="tmp" value="tmp"/>  
    <property name="build.dir" location="${tmp}/component/${project.name}"/>
    <property name="java.classes" location="${tmp}/component/${project.name}/classes"/>
    <property name="weblayout.dir" location="${tmp}/weblayout/resources/${project.name}"/>


    <path id="compile.classpath">
        <fileset dir="lib" includes="**/*.jar" />
        <fileset dir="lib/build" includes="*.zip" />
    </path>

    <target name="clean">
        <delete dir="${tmp}" />
    </target>

    <target name="init" depends="clean">
        <mkdir dir="${java.classes}" />
    </target>

    <target name="compile" depends="init">
        <javac srcdir="src" source="1.5" target="1.5" encoding="utf-8" includes="**/*.java" destdir="${java.classes}" classpathref="compile.classpath" />
    </target>

    <target name="copy-resources" depends="compile">

            //Lots of copying here

    </target>

    <target name="read.version" description="Parses the hda file for your version number">

        <property file="${project.name}.hda" prefix="hda"/>
        <propertyregex property="version" input="${hda.version}" regexp="\." replace="-" global="true" override="true"/>
        <var name="version2" value="${version}"/>

        <echo>${version}</echo>
        <echo>${version2}</echo>


    </target>

    <target name="zip" depends="copy-resources, read.version" description="Package component">

        <zip destfile="${project.name}-${version}.zip" basedir="${tmp}" />
        <delete dir="${tmp}" />

    </target>


</project>

Tarne:

<?xml version="1.0" ?>
<project default="tarne">

    <include file="build.xml"/>
    <property name="project.name" value="build.project.name"/>

    <target name="tarne">

        <antcall target="build.read.version" inheritRefs="true"></antcall>
        <property name="version" value="build.version"/>
        <property name="version2" value="build.version2"/>

        <echo>${version}</echo> 
        <echo>${version2}</echo>    



    </target>

</project>

And the output I get when I run tarne.xml is:

Buildfile: tarne.xml
tarne:
build.read.version:
     [echo] v1-0-1
     [echo] v1-0-1
     [echo] default_version_value
     [echo] default_version_value

Where the first 2 lines (v1-0-1) are from inside the read.version target of build.xml and the next 2 lines are from tarne.xml. The general idea is that I should be able to access the version number in my tarne.xml build script.

Any ideas on what's going wrong?

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

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

发布评论

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

评论(2

东北女汉子 2024-11-08 05:26:59

Antcall 不支持您打算执行的操作:

http://ant.apache.org/manual /Tasks/antcall.html
被调用的目标在新项目中运行;请注意,这意味着被调用目标设置的属性、引用等将不会保留回调用项目。

你可以尝试:

  <target name="tarne" depends="build.read.version">
  </target>

这会保留新的值。

Antcall does not support what you intend to do:

http://ant.apache.org/manual/Tasks/antcall.html :
The called target(s) are run in a new project; be aware that this means properties, references, etc. set by called targets will not persist back to the calling project.

you could try:

  <target name="tarne" depends="build.read.version">
  </target>

which would keep the new values.

半﹌身腐败 2024-11-08 05:26:59

尝试

<property name="version" value="${build.version}"/>         
 <property name="version2" value="${build.version2}"/> 

Try

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