ivy jar located in my dep lib

2019-09-08 05:38发布

how can I tell ant to find Ivy's jar in my own lib? ant just kept looking at it's home folder even when I've explicitly told it to find the jar somewhere else.

标签: ant ivy
2条回答
放荡不羁爱自由
2楼-- · 2019-09-08 06:25

I would recommend removing the ivy jar from the ANT home directory. (For some very odd reason it's not normally packaged with ANT).

Instead I recommend including a special task to ensure ivy is installed.

<available classname="org.apache.ivy.Main" property="ivy.installed"/> 

<target name="install-ivy" description="Install ivy" unless="ivy.installed">
    <mkdir dir="${user.home}/.ant/lib"/>
    <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.4.0/ivy-2.4.0.jar"/>
    <fail message="Ivy has been installed. Run the build again"/>
</target>

Analysis

The ANT manual outlines the order in which jars a loaded by ANT at startup.

  1. -lib jars in the order specified by the -lib elements on the command line
  2. jars from ${user.home}/.ant/lib (unless -nouserlib is set)
  3. jars from ANT_HOME/lib

This will always happen and unfortunately it won't matter what you do inside your build file.....

Jars in the ANT_HOME/lib

In my opinion, putting jars in the ANT_HOME effectively creates a bespoke installation of ANT. It makes your projects less portable across machines, and the customizations are frequently forgotten and undocumented.

So if you have control over the build server I would recommend removing any ANT tasks your find here.

Jars in the ${user.home}/.ant/lib

Placing jars here is less objectionable for the following reasons

  • Directory owned by the user running the build
  • Can be ignored at run-time by by using the commandline option -nouserlib
  • The only jar I put here is ivy... All other jars exist in the ivy cache (including ANT tasks)
查看更多
We Are One
3楼-- · 2019-09-08 06:26

You can place Ivy binaries in some folder inside you project folder. For example, in my case, it's etc/build/. I put where ivy.jar and jsch.jar.

After that provide the correct namespace in project defenfition and load Ivy.

<project name="somename" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">
    <target name="ivy-load">
        <path id="ivy.lib.path">
            <pathelement location="${basedir}/etc/build/ivy.jar"/>
            <pathelement location="${basedir}/etc/build/jsch.jar"/>
        </path>
        <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
    </target>
    <target name="ivy-init" depends="ivy-load">
        <ivy:settings file="${basedir}/etc/ivysettings/ivysettings.xml"/>
        <ivy:resolve conf="${ivy.conf}"/>
    </target>
    ...
</project>
查看更多
登录 后发表回答