Apache Ivy 简明教程

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.