如何可以在项目之间我最好的份额Ant目标? [英] How can I best share Ant targets between projects?

查看:262
本文介绍了如何可以在项目之间我最好的份额Ant目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有到项目之间共享蚂蚁目标的行之有效的方法是什么?我有一个解决方案,目前,但它是一个有点不雅。下面是我在做什么为止。

我有一个名为文件常春藤tasks.xml 托管在我们的网络上的一个服务器上。此文件包含,其他目标,任务样板管理项目依赖与常春藤之一。例如:

 <项目名称=蚁常春藤任务默认值=的init-常春藤
         的xmlns:常春藤=的antlib:org.apache.ivy.ant>
  ...
  <目标名称=常春藤下载除非=skip.ivy.download>
    < MKDIR DIR =$ {} ivy.jar.dir/>
    <回声消息=安装常春藤.../>
    <获得src=\"http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar\"
         DEST =$ {} ivy.jar.fileusetimestamp =真/>
  < /目标与GT;  <目标名称=常春藤INIT取决于=常春藤下载
          说明= - >定义ivy任务和负载全局设置>
    &所述;路径ID =ivy.lib.path>
      <文件集DIR =$ {} ivy.jar.dir包括=*罐子。/>
    < /路径>
    <的taskdef资源=组织/阿帕奇/常春藤/ ANT / antlib.xml
             URI =的antlib:org.apache.ivy.ant
             classpathref =ivy.lib.path/>
    <常春藤:设置URL =HTTP://myserver/ivy/settings/ivysettings-user.xml/>
  < /目标与GT;
  ...
< /项目>

该文件托管的原因是因为我的想:


  • 检查文件到任何需要它的每一个项目 - 这将导致重复,使得维护更加努力的目标

  • 有我的build.xml取决于检查出从源头控制项目 - 这将使构建具有顶级更多的XML只是访问文件

我做这个文件在我的项目build.xmls是沿着线:

 <属性名=download.dir位置=下载/>
< MKDIR DIR =$ {} download.dir/>
<回声消息=下载导入文件为$ {} download.dir/><获得SRC =HTTP://myserver/ivy/ivy-tasks.xml目标=$ {} download.dir /ivy-tasks.xmlusetimestamp =真/>
<导入文件=$ {} download.dir /ivy-tasks.xml/>

关于这个脏的是,我必须做上述步骤的目标的外面,因为的导入任务必须在顶层。另外,我还必须包括所有需要它的的build.xml文件,这个XML(即仍然有一些重复的量)。

在此基础之上,因此可能会出现我可能,我想进口的普通(非常春藤)任务的其他情形。如果我是提供使用常春藤的依赖管理我仍然有问题,因为到时候我不得不解决的依赖关系,我将不得不在我的build.xml的目标内,而这些任务无法进口(因要约束上面提到的)。

有没有更好的解决办法是什么,我试图完成?


解决方案

如果您正在使用ANT 1.8+,那么你可以只直接从托管位置导入的build.xml文件。

<一个href=\"http://ant.apache.org/manual/Tasks/import.html\">http://ant.apache.org/manual/Tasks/import.html


  

由于蚂蚁1.8.0任务也可以
  从URL中导入资源或
  资源类路径(这是网址,
  真)。如果你需要知道
  当前构建文件的来源有
  是一个文件,也可以请教网址
  物业ant.file.type.projectname
  (使用与上述相同的例子
  ant.file.type.builddocs),它要么
  有值文件或URL。


 &LT;! -  importing.xml  - &GT;
&LT;项目名称=进口的basedir =。默认=...&GT;
  &LT;导入文件=HTTP://myserver/ivy/ivy-tasks.xml/&GT;
&LT; /项目&GT;

Is there a well-established way to share Ant targets between projects? I have a solution currently, but it's a bit inelegant. Here's what I'm doing so far.

I've got a file called ivy-tasks.xml hosted on a server on our network. This file contains, among other targets, boilerplate tasks for managing project dependencies with Ivy. For example:

<project name="ant-ivy-tasks" default="init-ivy"
         xmlns:ivy="antlib:org.apache.ivy.ant">
  ...
  <target name="ivy-download" unless="skip.ivy.download">
    <mkdir dir="${ivy.jar.dir}"/>
    <echo message="Installing ivy..."/>
    <get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar"
         dest="${ivy.jar.file}" usetimestamp="true"/>
  </target>

  <target name="ivy-init" depends="ivy-download"
          description="-> Defines ivy tasks and loads global settings">
    <path id="ivy.lib.path">
      <fileset dir="${ivy.jar.dir}" includes="*.jar"/>
    </path>
    <taskdef resource="org/apache/ivy/ant/antlib.xml"
             uri="antlib:org.apache.ivy.ant"
             classpathref="ivy.lib.path"/>
    <ivy:settings url="http://myserver/ivy/settings/ivysettings-user.xml"/>
  </target>
  ...
</project>

The reason this file is hosted is because I don't want to:

  • Check the file into every project that needs it - this will result in duplication, making maintaining the targets harder.
  • Have my build.xml depend on checking out a project from source control - this will make the build have more XML at the top-level just to access the file.

What I do with this file in my projects' build.xmls is along the lines of:

<property name="download.dir" location="download"/>
<mkdir dir="${download.dir}"/>
<echo message="Downloading import files to ${download.dir}"/>

<get src="http://myserver/ivy/ivy-tasks.xml" dest="${download.dir}/ivy-tasks.xml" usetimestamp="true"/>
<import file="${download.dir}/ivy-tasks.xml"/>

The "dirty" part about this is that I have to do the above steps outside of a target, because the import task must be at the top-level. Plus, I still have to include this XML in all of the build.xml files that need it (i.e. there's still some amount of duplication).

On top of that, there might be additional situations where I might have common (non-Ivy) tasks that I'd like imported. If I were to provide these tasks using Ivy's dependency management I'd still have problems, since by the time I'd have resolved the dependencies I would have to be inside of a target in my build.xml, and unable to import (due to the constraint mentioned above).

Is there a better solution for what I'm trying to accomplish?

解决方案

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>

这篇关于如何可以在项目之间我最好的份额Ant目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆