Apache Ivy 简明教程

Apache IVY - Quick Guide

Apache IVY - Overview

Apache Ivy 是一款非常流行也非常强大的依赖项管理工具,用于以与 Apache Maven 管理依赖项相同的方式,在基于 ANT 的项目中管理依赖项。

Apache Ivy is a very popular and very powerful dependency management tool used to manage dependencies in ANT based projects in the same fashion, how Apache Maven manages dependencies.

Apache Ivy 基于 Apache ANT,遵循相同的设计原则,是 Apache ANT 的一个子项目,并由 Apache ANT 社区积极管理和支持。

Apache Ivy is Apache ANT based, follows same design principles, is a subproject of Apache ANT and is actively managed and supported by Apache ANT Community.

Features

以下是 Apache Ivy 的重要功能。

Following are the important features of Apache Ivy.

  1. ANT Based − Apache Ivy provides a dependencies management capability to ANT based projects. It is very simple to use as well.

  2. Dependency Reports − Apache Ivy provides options to print dependencies graph in html as well as in reports format.

  3. Non-intrusive − Apache Ivy don’t impose any restrictions as to be part of distribution. Even build files are not dependent on Apache Ivy.

  4. Highly Flexible − Apache Ivy provides lots of default configurations and can be configured as per the requirement very easily.

  5. Extendible − Apache Ivy can be extended easily. You can define your own repository, conflict resolvers and latest strategy.

  6. Performance − Apache Ivy is built towards performance. It keeps a cache of library already downloaded. Looks into local repositories first to resolve dependencies than look into other repositories.

  7. Transitive Dependencies − Apache Ivy automatically manages transitive dependencies if one project or library depends upon other library which may need another library.

  8. Maven Repository − Apache Ivy follows conventions similar to Maven repository conventions. Apache Ivy can resolve dependencies using maven global repository.

  9. Maven 2 POMs − Apache Ivy can read Maven 2 POMs as module descriptors, can set ivy as module descriptor. Thus it makes easy to migrate existing projects to IVY managed projects.

  10. Publishing − Apache Ivy provides supports to publish your project and simplifies the multi-project environment deployment process.

  11. Free to Use − Apache Ivy is open source and is free to use.

  12. Documentation − Apache Ivy has a very detailed documentation and tutorials available to learn.

Apache IVY - Environment Setup

Apache Ivy 对你的电脑只要求安装了 Java 和 ANT。

Apache Ivy needs Java and ANT installed on your machine as the only requirement.

Apache Ant 是在已通过开放源代码计划认证的全面开源许可证“Apache 软件许可证”之下分发的。

Apache Ant is distributed under the Apache Software License, a fully-fledged open source license certified by the open source initiative.

可在以下位置找到包含其全部源代码、类文件和文档的最新 Apache Ant 版本: http://ant.apache.org.

The latest Apache Ant version, including its full-source code, class files, and documentation can be found at http://ant.apache.org.

Installing Apache Ant

假设您已在计算机上下载并安装了 Java 开发工具包 (JDK)。如果没有,请按照说明操作 here

It is assumed that you have already downloaded and installed Java Development Kit (JDK) on your computer. If not, please follow the instructions here.

  1. Ensure that the JAVA_HOME environment variable is set to the folder where your JDK is installed.

  2. Download the binaries from https://ant.apache.org

  3. Unzip the zip file to a convenient location c:\folder. using Winzip, winRAR, 7-zip or similar tools.

  4. Create a new environment variable called ANT_HOME that points to the Ant installation folder, in this case c:\apache-ant-1.10.12-bin folder.

  5. Append the path to the Apache Ant batch file to the PATH environment variable. In our case this would be the c:\apache-ant-1.10.12-bin\bin folder.

Verifying Apache Ant Installation

在计算机中验证 Apache Ant 的安装是否成功,请在命令提示符中键入 ant。

To verify the successful installation of Apache Ant on your computer, type ant on your command prompt.

您应该看到类似于 − 的输出

You should see an output similar to −

C:\>ant -version
Apache Ant(TM) version 1.10.12 compiled on October 13 2021

如果您没有看到以上输出结果,请验证您是否已经正确地按照安装步骤操作。

If you do not see the above output, then please verify that you have followed the installation steps properly.

Installing Apache Ivy

  1. Download the binaries from https://ant.apache.org/ivy

  2. Unzip the zip file to a convenient location c:\folder. using Winzip, winRAR, 7-zip or similar tools.

  3. Copy the ivy-2.5.0.jar to c:\apache-ant-1.10.12-bin/lib folder.

Verifying Apache Ivy Installation

要在计算机上验证 Apache Ivy 是否成功安装,请在文件夹 E: > ivy 中创建以下构建文件。

To verify the successful installation of Apache Ivy on your computer, create following build file in a folder E: > ivy.

<project name="test ivy installation"
   default="test" xmlns:ivy="antlib:org.apache.ivy.ant">
   <target name="test" description="Test ivy installation">
      <ivy:settings />
   </target>
</project>

您应该看到类似于 − 的输出

You should see an output similar to −

C:\>ant
Buildfile: E:\ivy\build.xml

test:

BUILD SUCCESSFUL
Total time: 2 seconds

Installing Eclipse

本教程还涵盖了 Ant 与 Eclipse IDE 的集成。因此,如果您尚未安装 Eclipse,请下载并安装 Eclipse

This tutorial also covers integration of Ant with Eclipse IDE. Hence, if you have not installed Eclipse already, please download and install Eclipse

要安装 Eclipse −

To install Eclipse −

  1. Download the latest Eclipse binaries from www.eclipse.org

  2. Unzip the Eclipse binaries to a convenient location, say c:\folder

  3. Run Eclipse from c:\eclipse\eclipse.exe

Apache IVY - Terminology

考虑以下示例 ivy.xml 来理解 Ivy 术语。

Consider the following example ivy.xml to understand Ivy terminology.

<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
   <info organisation="com.tutorialspoint" module="ivy-test" status="integration">
   </info>
   <dependencies>
      <dependency org="commons-lang" name="commons-lang" rev="2.6" />
   </dependencies>
</ivy-module>

Ivy Terms

以下是在 Ivy 生态系统中重要的术语。

Following are the important terms of Ivy Eco-System.

  1. Organisation − As name suggests, it refers to the name of the company, individual developer or team name who creates the project or library. For example, com.tutorialspoint.

  2. Module − As name suggests, it refers to the reusable unit or module. A module generally have a version attached to it. For example commons-lang, or ivy-test etc.

  3. Module Descriptor − Module descriptor refers to ivy.xml file which describes a module. A module descriptor contains the identifier (org, name, branch and version), artifacts published, configurations and dependencies.

  4. Artifact − Artifact refers to a single file as deliverable. For example, a jar file. Artifact can be of type: zip, gz etc. Jar, Source Jar, Javadoc Jar are various artifacts of a module.

  5. Type − Type identifies the artifact category like jar, war , src, doc etc.

  6. Artifact file name extension − Artifact extension like .jar, ,zip, .gz etc.

  7. Module Revision − A unique revision number of the module or its version number.

  8. Status of Revision − Status of revision indicates the stability of the revision. Following are the important value of status − integration − Represents continous development, nightly build etc. milestone − Represents a distribution but not finalized. release − Represents tested and completed, a major version.

  9. Repository − Similar to Maven repositories, repository represents a distribution site where ivy can search a library, artifacts, modules etc. A repository can be public, private or shared.

  10. Ivy Settings − Apache Ivy follows Maven principles and comes with lot of default configurations. Default settings can be overridden by defining a ivysettings.xml file.

Apache IVY - Settings File

Apache Ivy 遵循 Maven 原则,并附带许多默认配置。可以通过定义 ivysettings.xml 文件来覆盖默认设置。

Apache Ivy follows Maven principles and comes with lot of default configurations. Default settings can be overridden by defining a ivysettings.xml file.

<ivysettings>
   <properties file="${ivy.settings.dir}/ivysettings-file.properties" />
   <settings defaultCache="${cache.dir}" defaultResolver="ibiblio" checkUpToDate="false" />
   <resolvers>
      <ibiblio name="ibiblio" />
      <filesystem name="internal">
         <ivy pattern="${repository.dir}/[module]/ivy-[revision].xml" />
         <artifact pattern="${repository.dir}/[module]/[artifact]-[revision].[ext]" />
      </filesystem>
   </resolvers>
   <modules>
      <module organisation="tutorialspoint" name=".*" resolver="internal" />
   </modules>
</ivysettings>

Tags of Ivy Settings File

以下是 Ivy 设置文件的重要标签。

Following are the important tags of Ivy Setting file.

  1. property − To set an ivy variable. Cardinality: 0..n

  2. properties − To set an ivy variables using properties file. Cardinality: 0..n

  3. settings − To configure ivy with default values. Cardinality: 0..1

  4. include − To include another settings file. Cardinality: 0..n

  5. classpath − To add a location in the classpath used to load plugins. Cardinality: 0..n

  6. typedef − To define new types in ivy. Cardinality: 0..n

  7. lock-strategies − To define lock strategies. Cardinality: 0..1

  8. caches − To define repository cache managers. Cardinality: 0..1

  9. latest-strategies − To define latest strategies. Cardinality: 0..1

  10. parsers − To define module descriptor parsers. Cardinality: 0..1

  11. version-matchers − To define new version matchers. Cardinality: 0..1

  12. triggers − To register triggers on ivy events. Cardinality: 0..1

  13. namespaces − To define new namespaces. Cardinality: 0..1

  14. macrodef − To define a new macro resolver. Cardinality: 0..n

  15. resolvers − To define dependency resolvers. Cardinality: 0..1

  16. conflict-managers − To define conflicts managers. Cardinality: 0..1

  17. modules − To define rules between modules and dependency resolvers. Cardinality: 0..1

  18. outputters − To define the list of available report outputters. Cardinality: 0..1

  19. statuses − To define the list of available statuses. Cardinality: 0..1

Apache IVY - Eclipse Ivy Plugin

IvyDE 是 Apache 提供的 Eclipse 插件。要安装 IvyDE,请启动 Eclipse 并导航至帮助 > 安装新软件。它会显示可用软件窗口。输入 IvyDE 更新站点 * [role="bare"] [role="bare"]http://www.apache.org/dist/ant/ivyde/updatesite/* ,然后按回车键。它会显示以下插件。

IvyDE is an Eclipse plugin provided by Apache. To install IvyDE, start Eclipse and navigate to Help > Install New Software. It displays the Available Softwares window. Enter IvyDE update site * [role="bare"]http://www.apache.org/dist/ant/ivyde/updatesite/* and press enter key. It displays the following plugins.

available software

单击下一步,你将看到以下屏幕。

Click Next and you will see the following screen.

installation

如果你在安装插件时遇到任何错误,只需重启进程。成功安装后,你将在 eclipe 中看到插件。

If you are facing any error while installing the plugin then just restart the process. After successful installation, you will see the plugin in eclipe.

ivy plugin

现在你可以使用 Eclipse 和 Ivy 进行依赖关系管理。

Now you can do the dependency management using Eclipse and Ivy.

Apache IVY - Resolve Task

解析任务用于解析 ivy.xml 中描述的依赖项,下载并将它们放入 ivy 缓存中。

Resolve task is used to resolve dependencies described in ivy.xml, download and put them in ivy cache.

我们首先在 *E: > ivy > src > com > tutorialspoint * 文件夹中创建一个 Java 文件 Tester.java,该文件将充当 ant 项目的源文件夹。

Let’s first create a java file Tester.java in *E: > ivy > src > com > tutorialspoint * folder which will act as source folder for ant project.

Application.java

Application.java

package com.tutorialspoint;
import org.apache.commons.lang.StringUtils;
public class Application {
   public static void main(String[] args) {
      String string = StringUtils.upperCase("Ivy Beginner Guide");
      System.out.println(string);
   }
}

以上类使用 apache commons lang 库来使用其类 StringUtils。Ivy 应下载此库,因此应在 ivy.xml 的依赖项部分下定义它。以下是创建的位于 * E: > ivy * 文件夹中的 ivy.xml。

Above class is using apache commons lang library to use its class StringUtils. Ivy should download this library and thus it should be defined under dependencies section in ivy.xml. Following is the ivy.xml created in * E: > ivy * folder.

ivy.xml

ivy.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
   <info
      organisation="com.tutorialspoint"
      module="test"
      status="integration">
   </info>
   <dependencies>
      <dependency org="org.apache.commons" name="commons-lang3" rev="3.9"/>
   </dependencies>
</ivy-module>

以下是重要术语。

Following are the important terms.

  1. ivy-module − Root element to identify ivy version, namespace etc.

  2. info − element to identify the project as a unique entity. organisation − name of the organization module − name of the module status − status like release, integration or milestone.

  3. dependencies − element to contain project dependencies as dependency tags which has following attributes. org − name of the dependency’s organization name − name of the dependency. rev − version of the dependency.

build.xml

build.xml

<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
   </target>
</project<

以下是重要术语。

Following are the important terms.

  1. project − Root element to identify project name, default task namespace for ivy etc.

  2. target − target element to create a new task and its description. This contains an ivy resolve task. When ant builds the project, it runs the ivy resolve task which then resolves the dependencies using ivy.

Building the project

因为我们已准备好所有文件。只需转到控制台。导航至 E:\ivy 文件夹并运行 ant 命令。

As we’ve all the files ready. Just go the console. Navigate to *E: > ivy * folder and run the ant command.

E:\ivy > ant

Ivy 将执行操作,解析依赖关系,您将看到以下结果。

Ivy will come into action, resolving the dependencies, you will see the following result.

Buildfile: E:\ivy\build.xml
resolve:
[ivy:resolve] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy
/ ::
[ivy:resolve] :: loading settings :: url = jar:file:/E:/Apache/apache-ant-1.9.14
/lib/ivy-2.5.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:resolve] :: resolving dependencies :: com.tutorialspoint#test;working@Acer-
PC
[ivy:resolve]   confs: [default]
[ivy:resolve]   found commons-lang#commons-lang;2.6 in public
[ivy:resolve]   found junit#junit;3.8.1 in public
[ivy:resolve] :: resolution report :: resolve 375ms :: artifacts dl 79ms
      ---------------------------------------------------------------------
      |                  |            modules            ||   artifacts   |
      |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
      ---------------------------------------------------------------------
      |      default     |   2   |   2   |   0   |   0   ||   4   |   0   |
      ---------------------------------------------------------------------
[ivy:retrieve] :: retrieving :: com.tutorialspoint#test [sync]
[ivy:retrieve]  confs: [default]
[ivy:retrieve]  0 artifacts copied, 2 already retrieved (0kB/101ms)
BUILD SUCCESSFUL
Total time: 1 second
E:\ivy>

Resolve Output

以下是重要术语。

Following are the important terms.

  1. conf − configuration, in our case we are using default configuration.

  2. modules − indicates the total number of modules, downloaded modules etc.

  3. artifacts − indicates the total number of artifacts, downloaded artifacts etc.

你可以在 * ${ivy.default.ivy.user.dir} > .ivy2 > cache* 文件夹中的 Ivy 缓存默认位置验证下载的文件。而 ${ivy.default.ivy.user.dir} 默认为用户主页:$HOME。

You can verify the downloaded files in ivy cache’s default location in * ${ivy.default.ivy.user.dir} > .ivy2 > cache* folder. And ${ivy.default.ivy.user.dir} is by default user home: $HOME.

Apache IVY - Install Task

安装任务用于在解析器中安装模块及其依赖项。当要下载公共构建产出并在私有存储库中使用时,将用到该模块。默认情况下,用户本地存储库就是其私有存储库,位于 ${ivy.default.ivy.user.dir}/local。

Install task is used to install a module and its dependencies in a resolver. It is used when a public artifact is to be downloaded and used in private repository. By default, a user local repository is his/her private repository and is present in ${ivy.default.ivy.user.dir}/local.

让我们按照 IVY - Resolve Task 章节中的描述创建 Tester.java、build.xml 和 ivy.xml。

Let’s create Tester.java, build.xml and ivy.xml as described in IVY - Resolve Task chapter.

更新 build.xml 以使用 ivy install 任务。

Update the build.xml to use the ivy install task.

build.xml

build.xml

<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
   </target>
   <target name="install" description="install dependencies">
      <ivy:install organisation="commons-lang" module="commons-lang"
         revision="2.6" transitive="true" overwrite="false"
         from="public" to="local" />
   </target>
</project>

以下是重要术语。

Following are the important terms.

  1. organisation − name of the organization.

  2. module − module name of the project.

  3. revision − version of the project.

  4. from − from repository type.

  5. to − to repository type.

Building the project

因为我们已准备好所有文件。只需转到控制台。导航至 E:\ivy 文件夹并运行 ant 命令。

As we’ve all the files ready. Just go the console. Navigate to *E: > ivy * folder and run the ant command.

E:\ivy > ant install

Ivy 将执行操作,解析依赖关系,您将看到以下结果。

Ivy will come into action, resolving the dependencies, you will see the following result.

E:\ivy > ant install
Buildfile: E:\ivy\build.xml
install:
[ivy:install] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy
/ ::
[ivy:install] :: loading settings :: url = jar:file:/E:/Apache/apache-ant-1.9.14
/lib/ivy-2.5.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:install] :: installing commons-lang#commons-lang;2.6 ::
[ivy:install] :: resolving dependencies ::
[ivy:install]   found commons-lang#commons-lang;2.6 in public
[ivy:install]   found junit#junit;3.8.1 in public
[ivy:install] :: downloading artifacts to cache ::
[ivy:install] :: installing in local ::
[ivy:install]   published commons-lang to C:\Users\Acer\.ivy2\local\commons-lang
\commons-lang\2.6.part\sources\commons-lang.jar
[ivy:install]   published commons-lang to C:\Users\Acer\.ivy2\local\commons-lang
\commons-lang\2.6.part\jars\commons-lang.jar
[ivy:install]   published commons-lang to C:\Users\Acer\.ivy2\local\commons-lang
\commons-lang\2.6.part\javadocs\commons-lang.jar
[ivy:install]   published ivy to C:\Users\Acer\.ivy2\local\commons-lang\commons-
lang\2.6.part\ivys\ivy.xml
[ivy:install]   publish committed: moved C:\Users\Acer\.ivy2\local\commons-lang\
commons-lang\2.6.part
[ivy:install]           to C:\Users\Acer\.ivy2\local\commons-lang\commons-lang\2
.6
[ivy:install]   published junit to C:\Users\Acer\.ivy2\local\junit\junit\3.8.1.p
art\jars\junit.jar
[ivy:install]   published ivy to C:\Users\Acer\.ivy2\local\junit\junit\3.8.1.par
t\ivys\ivy.xml
[ivy:install]   publish committed: moved C:\Users\Acer\.ivy2\local\junit\junit\3
.8.1.part
[ivy:install]           to C:\Users\Acer\.ivy2\local\junit\junit\3.8.1
[ivy:install] :: install resolution report ::
[ivy:install] :: resolution report :: resolve 0ms :: artifacts dl 21ms
      ---------------------------------------------------------------------
      |                  |            modules            ||   artifacts   |
      |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
      ---------------------------------------------------------------------
      |      default     |   2   |   0   |   0   |   0   ||   4   |   0   |
      ---------------------------------------------------------------------
BUILD SUCCESSFUL
Total time: 43 seconds

可以在 ivy 缓存的默认本地存储库位置 ${ivy.default.ivy.user.dir}> .ivy2 > local 目录中验证下载的文件。

You can verify the downloaded files in ivy cache’s default local repository location * ${ivy.default.ivy.user.dir} > .ivy2 > local* directory.

Apache IVY - Retrieve Task

检索任务用于将依赖项解析到项目工作空间中的指定位置。

retrieve task is used to resolve dependencies to a specified location in project workspace.

让我们按照 IVY - Resolve Task 章节中的描述创建 Tester.java、build.xml 和 ivy.xml。

Let’s create Tester.java, build.xml and ivy.xml as described in IVY - Resolve Task chapter.

更新 build.xml, 以使用 ivy retrieve 任务。

Update the build.xml to use the ivy retrieve task.

build.xml

build.xml

<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
      <ivy:retrieve sync="true" type="jar" />
   </target>
</project>

以下是重要术语。

Following are the important terms.

  1. sync − sync true ensure that lib directory is up-to-date and any extra file gets deleted.

  2. type − type directs ivy to copy only specified type of artifacts like jar. Source jar, javadoc jar will be ignored. type for source jar is src or source and doc or bundle for javadoc jar.

在项目 lib 目录中,retrieve 任务默认情况下复制已解析依赖项,且可以通过 pattern 属性更改。

retrieve tasks copies the resolved dependencies in the lib directory of the project by default and can be changed using pattern attribute.

Building the project

因为我们已准备好所有文件。只需转到控制台。导航至 E:\ivy 文件夹并运行 ant 命令。

As we’ve all the files ready. Just go the console. Navigate to *E: > ivy * folder and run the ant command.

E:\ivy > ant

Ivy 将执行操作,解析依赖关系,您将看到以下结果。

Ivy will come into action, resolving the dependencies, you will see the following result.

Buildfile: E:\ivy\build.xml
resolve:
[ivy:resolve] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy
/ ::
[ivy:resolve] :: loading settings :: url = jar:file:/E:/Apache/apache-ant-1.9.14
/lib/ivy-2.5.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:resolve] :: resolving dependencies :: com.tutorialspoint#test;working@Acer-
PC
[ivy:resolve]   confs: [default]
[ivy:resolve]   found commons-lang#commons-lang;2.6 in public
[ivy:resolve]   found junit#junit;3.8.1 in public
[ivy:resolve] :: resolution report :: resolve 316ms :: artifacts dl 18ms
      ---------------------------------------------------------------------
      |                  |            modules            ||   artifacts   |
      |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
      ---------------------------------------------------------------------
      |      default     |   2   |   2   |   0   |   0   ||   4   |   0   |
      ---------------------------------------------------------------------
[ivy:retrieve] :: retrieving :: com.tutorialspoint#test [sync]
[ivy:retrieve]  confs: [default]
[ivy:retrieve]  0 artifacts copied, 2 already retrieved (0kB/2756ms)
BUILD SUCCESSFUL
Total time: 31 seconds

你可以在项目 lib 目录中验证下载的文件。

You can verify the downloaded files in project lib directory.

Apache IVY - Cachepath Task

用作创建 ANT 类路径的 cachepath 任务,该类路径包含高速缓存中存在的已解析工件。由于 ANT 需要将 jar 设置为编译 Java 文件的类路径,因此 Ivy cachepath 将构建类路径。

cachepath task is used to create an ANT classpath with resolved artifacts present in the cache. As ANT needs jars to be classpath to compile java files, Ivy cachepath builds the classpath.

让我们按照 IVY - Resolve Task 章节中的描述创建 Tester.java、build.xml 和 ivy.xml。

Let’s create Tester.java, build.xml and ivy.xml as described in IVY - Resolve Task chapter.

更新 build.xml, 以使用 ivy retrieve 任务。

Update the build.xml to use the ivy retrieve task.

build.xml

build.xml

<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
      <ivy:cachepath pathid="new.classpath" />
   </target>
   <target name="compile" depends="resolve" description="Compile">
      <mkdir dir="build/classes" />
      <javac srcdir="src" destdir="build/classes">
         <classpath refid="new.classpath" />
      </javac>
   </target>
</project>

以下是重要术语。

Following are the important terms.

  1. pathid − id of the classpath where cached jars are present.

在项目 lib 目录中,retrieve 任务默认情况下复制已解析依赖项,且可以通过 pattern 属性更改。

retrieve tasks copies the resolved dependencies in the lib directory of the project by default and can be changed using pattern attribute.

Building the project

因为我们已准备好所有文件。只需转到控制台。导航至 E:\ivy 文件夹并运行 ant 命令。

As we’ve all the files ready. Just go the console. Navigate to *E: > ivy * folder and run the ant command.

E:\ivy > ant compile

Ivy 将执行操作,解析依赖关系,您将看到以下结果。

Ivy will come into action, resolving the dependencies, you will see the following result.

Buildfile: E:\ivy\build.xml
resolve:
[ivy:resolve] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy
/ ::
[ivy:resolve] :: loading settings :: url = jar:file:/E:/Apache/apache-ant-1.9.14
/lib/ivy-2.5.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:resolve] :: resolving dependencies :: com.tutorialspoint#test;working@Acer-
PC
[ivy:resolve]   confs: [default]
[ivy:resolve]   found commons-lang#commons-lang;2.6 in public
[ivy:resolve]   found junit#junit;3.8.1 in public
[ivy:resolve] :: resolution report :: resolve 2314ms :: artifacts dl 15ms
      ---------------------------------------------------------------------
      |                  |            modules            ||   artifacts   |
      |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
      ---------------------------------------------------------------------
      |      default     |   2   |   2   |   0   |   0   ||   4   |   0   |
      ---------------------------------------------------------------------
compile:
   [javac] E:\ivy\build.xml:13: warning: 'includeantruntime' was not set, defau
lting to build.sysclasspath=last; set to false for repeatable builds
   [javac] Compiling 1 source file to E:\ivy\build\classes
BUILD SUCCESSFUL
Total time: 3 seconds

可以在项目构建目录中验证已编译类文件。

You can verify the compiled class file in project build directory.

Apache IVY - Publish Task

发布任务用于将当前工件及其解析的描述符文件发布到指定存储库。

publish task is used to publish current artifacts and its resolved descriptor files to mentioned repository.

让我们按照 IVY - Resolve Task 章节中的描述创建 Tester.java、build.xml 和 ivy.xml。

Let’s create Tester.java, build.xml and ivy.xml as described in IVY - Resolve Task chapter.

更新 build.xml 以使用 ivy 发布任务。首先,我们将创建一个 jar 文件,然后将其发布。

Update the build.xml to use the ivy publish task. First we’ll create a jar file and then publish it.

build.xml

build.xml

<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <property name = "build.dir" value = "build"/>
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
   </target>
   <target name = "jar">
      <jar destfile = "${build.dir}/lib/application.jar"
         basedir = "${build.dir}/classes">
         <manifest>
            <attribute name = "Main-Class" value = "com.tutorialspoint.Application"/>
         </manifest>
      </jar>
   </target>
   <target name="publish" depends="jar">
      <ivy:resolve />
      <ivy:publish resolver="local" pubrevision="1.0" overwrite="true">
         <artifacts pattern="${build.dir}/lib/[artifact].[ext]" />
      </ivy:publish>
   </target>
</project>

以下是重要术语。

Following are the important terms.

  1. resolver − resolver to be used for publication.

  2. pattern − pattern to locate the artifact.

此处发布任务首先构建 jar,然后解析依赖关系,设置信息,再将制品发布至本地存储库。

Here publish task first build the jar, then resolve the dependencies, set the information and then publish the artifact to local repository.

Building the project

因为我们已准备好所有文件。只需转到控制台。导航至 E:\ivy 文件夹并运行 ant 命令。

As we’ve all the files ready. Just go the console. Navigate to *E: > ivy * folder and run the ant command.

E:\ivy > ant publish

Ivy 将执行操作,解析依赖关系,您将看到以下结果。

Ivy will come into action, resolving the dependencies, you will see the following result.

E:\ivy > ant publish
Buildfile: E:\ivy\build.xml
jar:
publish:
[ivy:resolve] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy
/ ::
[ivy:resolve] :: loading settings :: url = jar:file:/E:/Apache/apache-ant-1.9.14
/lib/ivy-2.5.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:resolve] :: resolving dependencies :: com.tutorialspoint#test;1.0.0
[ivy:resolve]   confs: [default]
[ivy:resolve]   found commons-lang#commons-lang;2.6 in public
[ivy:resolve]   found junit#junit;3.8.1 in public
[ivy:resolve] :: resolution report :: resolve 121ms :: artifacts dl 15ms
      ---------------------------------------------------------------------
      |                  |            modules            ||   artifacts   |
      |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
      ---------------------------------------------------------------------
      |      default     |   2   |   2   |   0   |   0   ||   4   |   0   |
      ---------------------------------------------------------------------
[ivy:publish] :: publishing :: com.tutorialspoint#test
[ivy:publish]   published application to C:\Users\Acer\.ivy2\local\com.tutorials
point\test\1.0\jars\application.jar
[ivy:publish]   published ivy to C:\Users\Acer\.ivy2\local\com.tutorialspoint\te
st\1.0\ivys\ivy.xml
BUILD SUCCESSFUL
Total time: 1 second

您可以在本地存储库中验证发布的 ivy 制品。

You can verify the publish ivy artifacts in local repository.

Apache IVY - Info Task

info 任务用于在文件中设置 ivy 专有信息,且无需进行任何依赖项解析就可使用。

info task is used to set ivy specific information in a file and can be used without any dependency resolution.

让我们按照 IVY - Resolve Task 章节中的描述创建 Tester.java、build.xml 和 ivy.xml。

Let’s create Tester.java, build.xml and ivy.xml as described in IVY - Resolve Task chapter.

更新 build.xml 以使用 ivy 发布任务。我们首先将创建 jar 文件,然后发布它。在发布任务之前,我们已使用 info 任务设置了所需的 ivy 信息。

Update the build.xml to use the ivy publish task. First we’ll create a jar file and then publish it. Before publish task, we’ve set the required ivy information using info task.

build.xml

build.xml

<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <property name = "build.dir" value = "build"/>
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
   </target>
   <target name = "jar">
      <jar destfile = "${build.dir}/lib/application.jar"
         basedir = "${build.dir}/classes">
         <manifest>
            <attribute name = "Main-Class" value = "com.tutorialspoint.Application"/>
         </manifest>
      </jar>
   </target>
   <target name="publish" depends="jar">
      <ivy:info file="ivy.xml" />
      <ivy:publish resolver="local" pubrevision="1.0" overwrite="true">
         <artifacts pattern="${build.dir}/lib/[artifact].[ext]" />
      </ivy:publish>
   </target>
</project>

此处发布任务首先构建 jar 文件,然后使用 ivy:info 任务设置信息,然后将工件发布到本地仓库。

Here publish task first build the jar, then set the information using ivy:info task and then publish the artifact to local repository.

Building the project

因为我们已准备好所有文件。只需转到控制台。导航至 E:\ivy 文件夹并运行 ant 命令。

As we’ve all the files ready. Just go the console. Navigate to *E: > ivy * folder and run the ant command.

E:\ivy > ant publish

Ivy 将执行操作,解析依赖关系,您将看到以下结果。

Ivy will come into action, resolving the dependencies, you will see the following result.

Buildfile: E:\ivy\build.xml
jar:
publish:
 [ivy:info] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy/
::
 [ivy:info] :: loading settings :: url = jar:file:/E:/Apache/apache-ant-1.9.14/l
ib/ivy-2.5.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:publish] :: publishing :: com.tutorialspoint#test
[ivy:publish]   published application to C:\Users\Acer\.ivy2\local\com.tutorials
point\test\1.0\jars\application.jar
[ivy:publish]   published ivy to C:\Users\Acer\.ivy2\local\com.tutorialspoint\te
st\1.0\ivys\ivy.xml
BUILD SUCCESSFUL
Total time: 0 seconds

如果我们不设置 info 任务,则发布任务将不起作用。使用下面修改后的 build.xml,并查看缺少组织属性等错误。

If we do not put the info task then publish task will not work. Use the below modified build.xml and see the error for missing organization attribute and so on.

build.xml

build.xml

<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <property name = "build.dir" value = "build"/>
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
   </target>
   <target name = "jar">
      <jar destfile = "${build.dir}/lib/application.jar"
         basedir = "${build.dir}/classes">
         <manifest>
            <attribute name = "Main-Class" value = "com.tutorialspoint.Application"/>
         </manifest>
      </jar>
   </target>
   <target name="publish" depends="jar">
      <ivy:publish resolver="local" pubrevision="1.0" overwrite="true">
         <artifacts pattern="${build.dir}/lib/[artifact].[ext]" />
      </ivy:publish>
   </target>
</project>

导航到 *E: > ivy * 文件夹并运行 ant 命令。

Navigate to *E: > ivy * folder and run the ant command.

E:\ivy > ant publish

Ivy 将执行操作,解析依赖关系,您将看到以下结果。

Ivy will come into action, resolving the dependencies, you will see the following result.

Buildfile: E:\ivy\build.xml
jar:
publish:
[ivy:publish] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy
/ ::
[ivy:publish] :: loading settings :: url = jar:file:/E:/Apache/apache-ant-1.9.14
/lib/ivy-2.5.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
BUILD FAILED
E:\ivy\build.xml:28: no organisation provided for ivy publish task: It can eithe
r be set explicitly via the attribute 'organisation' or via 'ivy.organisation' p
roperty or a prior call to <resolve/>
Total time: 3 seconds

Apache IVY - Resolvers

解析器用于查找下载信息库的位置。依赖关系解析器还处理常见任务。Ivy 提供了两种类型的解析器。

Resolvers are used to find locations from where a library is to be downloaded. A dependency resolver also handles common tasks. Ivy provides two types of Resolvers.

  1. Composite − A resolver which uses other resolvers to do its tasks.

  2. Standard − A resolver performs the required tasks.

Standard Resolvers

下表列出了标准解析器及其用法。

Following table lists down the standard resolvers and their usage.

Sr.No.

Name (Type) & Description

1

IvyRep (Standard) Locates Ivy files on ivyrep and artifacts on ibiblio.

2

IBiblio (Standard) Locates artifacts on ibiblio.

3

BinTray (Standard) Locates artifacts on bintray.

4

Packager (Standard) Locates Ivy files and packaging instructions via URLs, creates artifacts using instructions.

5

FileSystem (Standard) Locates Ivy files and artifacts on local file system.

6

URL (Standard) Locates Ivy files and artifacts on repositories which can be accessed using URLs.

7

MirroredURL (Standard) Locates Ivy files and artifacts on repositories which can be accessed using URLs from a mirror list.

8

VFS (Standard) Locates Ivy files and artifacts on repositories which can be accessed using Apache Commons VFS.

9

SSH (Standard) Locates Ivy files and artifacts on repositories which can be accessed using SSH.

10

SFTP (Standard) Locates Ivy files and artifacts on repositories which can be accessed using SFTP.

11

Jar (Standard) Locates Ivy files and artifacts on repositories within a jar.

12

Chain (Composite) Delegates the search to a chain of sub resolvers.

13

Dual (Composite) Delegates the search to a one resolver and artifacts to another.

14

OBR (Standard) Resolve modules as OSGi bundles listed by an OSGi obr.xml.

15

Eclipse updatesite (Standard) Resolve modules as OSGi bundles which are hosted on an Eclipse update site.

16

OSGi-agg (Composite) Delegates the search to a chain of sub resolvers supporting OSGi bundles.

让我们在 E: > ivy2 文件夹如下所描述类似的新项目中创建 Tester.java、build.xml 和 ivy.xml。在 E: > ivy2 下创建一个 settings 文件夹。在 settings 文件夹中创建 ivysettings.xml。

Let’s create Tester.java, build.xml and ivy.xml in a new project under E: > ivy2 folder similar to as described in IVY - Resolve Task chapter. Create a settings folder under E: > ivy2. Create the ivysettings.xml in the settings folder.

build.xml

build.xml

<project name="test" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
   <property name = "build.dir" value = "build"/>
   <property name = "base.dir" value = ""/>
   <target name="resolve" description="resolve dependencies">
      <ivy:resolve />
   </target>
   <target name="compile" depends="resolve" description="Compile">
      <mkdir dir="build/classes" />
      <javac srcdir="src" destdir="build/classes">
         <classpath refid="new.classpath" />
      </javac>
   </target>
</project>

ivy.xml

ivy.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
   <info organisation="org.apache" module="chained-resolvers"/>
   <dependencies>
      <dependency org="commons-lang" name="commons-lang" rev="2.6" conf="default"/>
      <dependency org="com.tutorialspoint" name="test" rev="1.0"/>
   </dependencies>
</ivy-module>

在这里,我们添加了两个依赖项,一个用于 commons-lang 库,另一个用于我们在 IVY - Publish Task 章节中发布的测试。

Here we’ve added two dependencies,one of commons-lang library and another as test which we published in IVY - Publish Task chapter.

ivysettings.xml

ivysettings.xml

<ivysettings>
   <settings defaultResolver="multiresolver"/>
   <resolvers>
      <chain name="multiresolver">
         <filesystem name="libraries">
            <artifact pattern="${ivy.settings.dir}/repository/[artifact]-[revision].[ext]"/>
         </filesystem>
         <ibiblio name="ibiblio" m2compatible="true"/>
      </chain>
   </resolvers>
</ivysettings>

在这里,我们添加了使用 chain resolver 创建的一个复合解析器,它有两个解析器,一个名为 library,用于在本地存储库中定位库,一个名为 ibiblio,用于在 maven 公共存储库中定位库。

Here we’ve added created a composite resolver using chain resolver which has two resolver, one named libraries to locate libaries on local repository and one named ibiblio on maven public repository.

Building the project

当我们准备好了所有文件。只需进入控制台。导航到 E: > ivy2 文件夹并运行 ant 命令。

As we’ve all the files ready. Just go the console. Navigate to *E: > ivy2 * folder and run the ant command.

E:\ivy > ant

Ivy 将执行操作,解析依赖关系,您将看到以下结果。

Ivy will come into action, resolving the dependencies, you will see the following result.

Buildfile: E:\ivy2\build.xml
resolve:
[ivy:resolve] :: Apache Ivy 2.5.0 - 20191020104435 :: https://ant.apache.org/ivy
/ ::
[ivy:resolve] :: loading settings :: url = jar:file:/E:/Apache/apache-ant-1.9.14
/lib/ivy-2.5.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
[ivy:resolve] :: resolving dependencies :: org.apache#chained-resolvers;working@
Acer-PC
[ivy:resolve]   confs: [default]
[ivy:resolve]   found commons-lang#commons-lang;2.6 in public
[ivy:resolve]   found com.tutorialspoint#test;1.0 in local
[ivy:resolve]   found junit#junit;3.8.1 in public
[ivy:resolve] downloading C:\Users\Acer\.ivy2\local\com.tutorialspoint\test\1.0\
jars\application.jar ...
[ivy:resolve] .. (1kB)
[ivy:resolve] .. (0kB)
[ivy:resolve]   [SUCCESSFUL ] com.tutorialspoint#test;1.0!application.jar (13ms)
[ivy:resolve] :: resolution report :: resolve 1085ms :: artifacts dl 22ms
      ---------------------------------------------------------------------
      |                  |            modules            ||   artifacts   |
      |       conf       | number| search|dwnlded|evicted|| number|dwnlded|
      ---------------------------------------------------------------------
      |      default     |   3   |   3   |   1   |   0   ||   5   |   1   |
      ---------------------------------------------------------------------
BUILD SUCCESSFUL
Total time: 9 seconds

在日志中你可以验证我们同时使用了本地和公共存储库解析器。

In the logs you can verify that we have used both local and public repository resolvers.

Apache IVY - Local Repository

本地存储库是用户的私有存储库。如果用户正在使用版本已在其他地方更改且存在重大更改的库,则非常有用。如果使用本地存储库,ivy 将在找到情况下使用本地中存在的库,并且不会查看公有或共享存储库。

A local repository is a private repository of a user. It is very useful in case a user is using a library whose version has been changed on other places and have breaking changes. In case of local repository, ivy will use the library present in the local if found and will not look into public or shared repositories.

Default Location

默认情况下,本地存储库位于 ${ivy.default.ivy.user.dir}/local 文件夹中。如果要更改它,请在 ant 文件中使用 ivy.local.default.root 变量。

By default, local repository is present in ${ivy.default.ivy.user.dir}/local folder. If you want to change it, the use the ivy.local.default.root variable in ant file.

build.xml

build.xml

<target name="resolve">
   <property name="ivy.local.default.root" value="/opt/ivy/repository/local"/>
   <ivy:resolve />
</target>

ivy 花样和制品花样等其他属性还可按如下方式定制:

Other properties like ivy pattern and artifact pattern can also be customized as follows −

build.xml

build.xml

<target name="resolve">
   <property name="ivy.local.default.root" value="/opt/ivy/repository/local"/>
   <property name="ivy.local.default.ivy.pattern" value="[module]/[revision]/ivy.xml"/>
   <property name="ivy.local.default.artifact.pattern" value="[module]/[revision]/[artifact].[ext]"/>
   <ivy:resolve />
</target>

Overriding ivysettings defaults

默认情况下,ivy 在 ivy.jar 中存在的 ivysettings.xml 中具有自己的配置。

By default ivy has its configurations in ivysettings.xml present in ivy.jar.

ivysettings.xml

ivysettings.xml

<ivysettings>
   <settings defaultResolver="default"/>
   <include url="${ivy.default.settings.dir}/ivysettings-public.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-local.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-default-chain.xml"/>
</ivysettings>

要覆盖本地存储库设置,请更新 ivysettings-local.xml 的内容。

To override local repository setting, update the contents of ivysettings-local.xml.

ivysettings-local.xml

ivysettings-local.xml

<ivysettings>
   <property name="ivy.local.default.root" value="${ivy.default.ivy.user.dir}/local" override="false"/>
   <property name="ivy.local.default.ivy.pattern" value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" override="false"/>
   <property name="ivy.local.default.artifact.pattern" value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" override="false"/>
   <resolvers>
      <filesystem name="local">
         <ivy pattern="${ivy.local.default.root}/${ivy.local.default.ivy.pattern}" />
         <artifact pattern="${ivy.local.default.root}/${ivy.local.default.artifact.pattern}" />
      </filesystem>
   </resolvers>
</ivysettings>

Apache IVY - Shared Repository

共享存储库是团队的团队级别共享存储库。通常会被组织覆盖。

A shared repository is a team level shared repository of a team. It is very common to be overridden in organizations.

Default Location

默认情况下,共享存储库位于 ${ivy.default.ivy.user.dir}/shared 文件夹中。如果你想进行更改,可在 ant 文件中使用 ivy.shared.default.root 变量。

By default, shared repository is present in ${ivy.default.ivy.user.dir}/shared folder. If you want to change it, the use the ivy.shared.default.root variable in ant file.

build.xml

build.xml

<target name="resolve">
   <property name="ivy.shared.default.root" value="/opt/ivy/repository/shared"/>
   <ivy:resolve />
</target>

ivy 花样和制品花样等其他属性还可按如下方式定制:

Other properties like ivy pattern and artifact pattern can also be customized as follows −

build.xml

build.xml

<target name="resolve">
   <property name="ivy.shared.default.root" value="/opt/ivy/repository/shared"/>
   <property name="ivy.shared.default.ivy.pattern" value="[organisation]/[module]/[revision]/ivy.xml"/>
   <property name="ivy.shared.default.artifact.pattern" value="[organisation]/[module]/[revision]/[artifact].[ext]"/>
   <ivy:resolve />
</target>

Overriding ivysettings defaults

默认情况下,ivy 在 ivy.jar 中存在的 ivysettings.xml 中具有自己的配置。

By default ivy has its configurations in ivysettings.xml present in ivy.jar.

ivysettings.xml

ivysettings.xml

<ivysettings>
   <settings defaultResolver="default"/>
   <include url="${ivy.default.settings.dir}/ivysettings-public.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-local.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-default-chain.xml"/>
</ivysettings>

若要覆盖共享存储库设置,更新 ivysettings-shared.xml 的内容。

To override shared repository setting, update the contents of ivysettings-shared.xml.

ivysettings-shared.xml

ivysettings-shared.xml

<ivysettings>
   <property name="ivy.shared.default.root" value="${ivy.default.ivy.user.dir}/shared" override="false"/>
   <property name="ivy.shared.default.ivy.pattern" value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" override="false"/>
   <property name="ivy.shared.default.artifact.pattern" value="[organisation]/[module]/[revision]/[type]s/[artifact].[ext]" override="false"/>
   <resolvers>
      <filesystem name="shared">
         <ivy pattern="${ivy.shared.default.root}/${ivy.shared.default.ivy.pattern}" />
         <artifact pattern="${ivy.shared.default.root}/${ivy.shared.default.artifact.pattern}" />
      </filesystem>
   </resolvers>
</ivysettings>

Apache IVY - Public repository

公共存储库是可通过互联网访问的存储库,并具有第三方模块。默认情况下,ibiblio 处于 m2 兼容模式,即公共存储库。它也称为 maven 2 公共存储库。

A public repository is a repository accessible using internet and have third party modules. By default ibiblio in m2 compatible mode is the public repository. It is also referred as maven 2 public repository.

Overriding ivysettings defaults

默认情况下,ivy 在 ivy.jar 中存在的 ivysettings.xml 中具有自己的配置。

By default ivy has its configurations in ivysettings.xml present in ivy.jar.

ivysettings.xml

ivysettings.xml

<ivysettings>
   <settings defaultResolver="default"/>
   <include url="${ivy.default.settings.dir}/ivysettings-public.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-local.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-default-chain.xml"/>
</ivysettings>

如要覆盖公共仓库设置,请更新 ivysettings-public.xml 的内容或在项目的设置文件夹中创建 ivysettings.xml。

To override public repository setting, update the contents of ivysettings-public.xml or create the ivysettings.xml in setting folder of your project.

ivysettings.xml

ivysettings.xml

<ivysettings>
   <settings defaultResolver="default"/>
   <include url="http://customserver/ivy/ivysettings-public.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-shared.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-local.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-main-chain.xml"/>
   <include url="${ivy.default.settings.dir}/ivysettings-default-chain.xml"/>
</ivysettings>

更新默认的 ivysetting-public.xml 内容。

Update the default ivysetting-public.xml contents.

Original - ivysetting-public.xml

Original - ivysetting-public.xml

<ivysettings>
   <resolvers>
      <ibiblio name="public" m2compatible="true"/>
   </resolvers>
</ivysettings>

Updated - ivysetting-public.xml

Updated - ivysetting-public.xml

<ivysettings>
   <resolvers>
      <filesystem name="public">
         <ivy pattern="/path/to/my/public/rep/[organisation]/[module]/ivy-[revision].xml" />
         <artifact pattern="/path/to/my/public/rep/[organisation]/[module]/[artifact]-[revision].[ext]" />
      </filesystem>
   </resolvers>
</ivysettings>