依赖管理工具 Ant & Ivy

Apache Ant

Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications.

Apache Ivy - Apache Ant 的一个子项目

Apache Ivy™ is a popular dependency manager focusing on flexibility and simplicity.

Ant & Ivy 操作示例

ivysettings.xml 文件用于配置从中下载有依赖关系的 JAR 文件的存储库。
示例:

 <ivysettings> 
  <settings defaultResolver="chained"/> 
  <resolvers> 
    <chain name="chained" returnFirst="true"> 
      <filesystem name="libraries"> 
        <artifact pattern="${ivy.conf.dir}/repository/[artifact]-[revision].[type]" /> 
      </filesystem> 
      <url name="integratebutton"> 
        <artifact pattern="http://www.integratebutton.com/repo/[organisation]/[module]/ 
           [revision]/[artifact]-[revision].[ext]" /> 
      </url> 
      <ibiblio name="ibiblio" /> 
      <url name="ibiblio-mirror"> 
        <artifact pattern="http://mirrors.ibiblio.org/pub/mirrors/maven2/[organisation]/ 
           [module]/[branch]/[revision]/[branch]-[revision].[ext]" /> 
      </url> 
    </chain> 
  </resolvers> 
 </ivysettings>

ivy.xml 文件用于描述项目对其他类库的依赖。
示例:

<ivy-module version="2.0">
    <info organisation="apache" module="hello-ivy"/>
    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.0"/>
        <dependency org="commons-cli" name="commons-cli" rev="1.0"/>
    </dependencies>
</ivy-module>

dependencies 部分让你定义依赖。这里这个模块依赖两个类库:commons-lang 和 commons-cli。如你所看到的,我们使用 org 和 name 属性来定义我们需要的依赖的组织和模块名。rev 属性用于明确说明你依赖的模块的修订版本。

为了知道如何填写这些属性,你需要知道你依赖的类库的准确信息。ivy 默认使用 maven2 仓库。我们推荐你使用 http://mvnrepository.com 来查找你需要的模块。一旦你找到它,你将得到如何在一个 maven POM 中声明依赖的细节。例如:

<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.0</version>
</dependency>

对应的 build.xml 文件包含一个 target 集合,容许解析在 ivy 文件中声明的依赖,编译并运行示例代码,生成依赖解析报告,并清理项目的缓存。

<target name="resolve" description="retrieve dependencies with ivy">
  <ivy:retrieve />
</target>

这里我们只使用了一个任务:retrieve 任务。没有任何属性,它将使用默认设置并查找名为 ivy.xml 的文件来获取依赖定义。

Ivy 依赖报告

Ivy 提供了一个任务,用于报告一个项目中的依赖文件。

<target name="ivy-report" depends="init-ivy"> 
  <ivy:report todir="${target.dir}/reports/ivy"/> 
</target>

引用:
让开发自动化: 利用 Ivy 管理依赖项
ANT、IVY 和 MAVEN
ivy教程(2)-快速开始

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,833评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,119评论 6 342
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,986评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,429评论 4 61
  • 继第一期《认识自我》主题分享会后,再次来到《收集世界》主题分享会,再次领略大神的风采, 青年才俊指点江山,慷慨激昂...
    木鱼飞阅读 3,180评论 1 0

友情链接更多精彩内容