Apache IVY - 信息任务



信息任务用于在文件设置 ivy 特定信息,并且无需任何依赖项解析即可使用。

让我们创建 Tester.java、build.xml 和 ivy.xm,如 IVY - 解析任务 章节所述。

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

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 任务设置信息,再将制品发布到本地存储库。

构建项目

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

E:\ivy > ant publish

Ivy 将开始执行操作,解析依赖项,您将看到以下结果。

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

如果我们没有放置信息任务,发布任务将无法正常工作。使用下面修改的 build.xm,查看缺少组织属性等错误。

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 命令。

E:\ivy > ant publish

Ivy 将开始执行操作,解析依赖项,您将看到以下结果。

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
广告