How can I best share Ant targets between projects?

若如初见. 提交于 2019-12-03 05:53:24

If you are using ANT 1.8+, then you could just import the build.xml directly from the hosted location.

http://ant.apache.org/manual/Tasks/import.html

Since Ant 1.8.0 the task can also import resources from URLs or classpath resources (which are URLs, really). If you need to know whether the current build file's source has been a file or an URL you can consult the property ant.file.type.projectname (using the same example as above ant.file.type.builddocs) which either have the value "file" or "url".

<!-- importing.xml -->
<project name="importing" basedir="." default="...">
  <import file="http://myserver/ivy/ivy-tasks.xml"/>
</project>
Vladimir

If you use Antlibs you can package them all inside a JAR file. Then simply copy this file into the ${ANT_HOME}/lib directory to use them.

After some additional searching, a possible solution would be to use SVN externals to check out specific required files that may be needed by the build.xml.

However, this would only work for users who are using Subversion as source control. It would still be nice to have a SCM-agnostic solution for users who aren't using Subversion, or another SCM that supports similar functionality.

What we've done is to create a project called 'bootstrap' which contains the various xml-files needed for the other projects at our office. So to set up your development environment you run build.xml in bootstrap which copies the xml-files (like your ivy-stuff, and other targets) to a known location, and then your build files include these like this:

<import file="${ant.bootstrap.dir}/ant-commons.xml" />
<import file="${ant.bootstrap.dir}/ant-commons-ear.xml" />

Our bootstrap build.xml contains this:

<target name="install">
        <fail unless="ant.bootstrap.dir" message="ant.bootstrap.dir ${missing.property.message}"/>
        <copy todir = "${ant.bootstrap.dir}">
            <fileset dir = "src/xml"/>
        </copy>
</target>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!