如何在不检查依赖项是否下载的情况下获取 ivy:cachepath 位置 [英] how to get ivy:cachepath location without checking if dependencies downloaded

查看:23
本文介绍了如何在不检查依赖项是否下载的情况下获取 ivy:cachepath 位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 build.xml 中有一个任务:

I have a task in my build.xml:

<target name="init" depends="init-ivy">
  ...
  <ivy:cachepath
      inline="true"
      module="jersey-container-servlet"
      organisation="org.glassfish.jersey.containers"
      pathid="jersey.classpath"
      revision="2.23.2" />
  ...
</target>

如有必要,此任务会下载 ivy(init-ivy 实际上是这样做的),然后调用 ivy 下载依赖项.它将 jersey.classpath 设置为结果.

This task downloads ivy if necessary (init-ivy does that actually) and then invokes ivy to download dependencies. It sets jersey.classpath as the result.

现在我的 build 任务依赖于 init 任务.所以每次我构建时,它都会检查是否需要安装依赖项.我想避免每次都检查依赖项,并将 buildinit 分开.但是 init 设置 jersey.classpath 并且 build 使用它.

Right now my build task depends on the init task. So every time I build, it checks if dependencies need to be installed. I want to avoid checking dependencies every time and have build separate from init. But init sets jersey.classpath and build uses it.

有没有办法从 ivy 获取 jersey.classpath 而不要求它检查依赖关系?在这种情况下不检查依赖项甚至是一个好习惯吗?

Is there a way to obtain jersey.classpath from ivy without asking it to check dependencies? Is it even a good practice to not check dependencies in this case?

推荐答案

正如在这个答案中所解释的,ivy 不会在每次运行时下载 jar.它在~/.ivy2/cache"下本地缓存它们:

As explained in this answer, ivy doesn't download jars every time it runs. It caches them locally under "~/.ivy2/cache":

其次,您在内联模式下使用 ivy,大概是为了避免创建 常春藤文件?ivy cachepath 被归类为 post resolve 任务,这意味着它会自动调用resolve 任务,在后台.内联模式的作用是告诉 ivy 每次都执行一个新的解析,如果你有多个类路径需要管理,这很浪费.

Secondly, you're using ivy in inline mode, presumably to avoid creating an ivy file? ivy cachepath is classified as post resolve task, which means it will automatically call the resolve task, in the background. What the inline mode does is tell ivy to perform a fresh resolve each time, which is wasteful if you have more than one classpath to manage.

你最后考虑过使用常春藤文件吗?对 resolve 任务的单个调用可以通过您项目的所有依赖项,在本地缓存此信息,然后确定是否需要下载文件.我建议总是解决依赖关系.它不会花费太多,而且可能在构建之间发生了变化(例如,如果您使用的是动态依赖项或 Maven 快照).

Finally have you considered using an ivy file? A single call to the resolve task can work thru all your project's dependencies, cache this information locally and then determine if files need to be downloaded or not. I would recommend always resolving dependencies. It doesn't cost much and it's possible that things have changed between builds (for example if you're using dynamic dependencies, or Maven snapshots).

这是我的常春藤标准 Ant 目标,如下所示:

Here are my standard Ant targets for ivy look like:

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

  <target name="resolve" depends="install-ivy">
    <ivy:resolve/>

    <ivy:report todir='${ivy.reports.dir}' graph='false' xml='false'/>

    <ivy:cachepath pathid="compile.path" conf="compile"/>
    <ivy:cachepath pathid="runtime.path" conf="runtime"/>
    <ivy:cachepath pathid="test.path"    conf="test"/>
  </target>

  <target name="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>

注意事项:

  • 名为resolve"的单个目标调用 ivy 来管理我的项目类路径.它还可以生成有用的文档报告
  • cachepath 任务正在使用 ivy 配置 用于对 ivy 文件中的依赖项进行分组或分类.这确实是一种能够在单一分辨率上节省时间的效率魔法.
  • 请注意 install-ivy 任务如何进行条件检查以确定是否安装了 ivy.由于复杂性,这个技巧对于项目的其余依赖项是不可行的.我的建议是确保 ivy 存在,然后用它来管理其他一切.(在引擎盖下,它会尽最大努力提高效率).我真的不明白为什么 Apache Ant 不捆绑 ivy jar.
  • Single target called "resolve" that calls ivy to manage my project classpaths. It also generates a useful report for documentation
  • The cachepath task is using ivy configurations to group or classify dependencies within the ivy file. This is really the efficiency magic that enables to save time on a single resolution.
  • Notice how the install-ivy task has a conditional check to determine if ivy is installed. This trick is not feasible with the rest of your project's dependencies due to complexity. My recommendation is ensure ivy exists and then use it to manage everything else. (Under the hood it'll do its best to be efficient). I don't really understand why Apache Ant doesn't bundle the ivy jar.

这篇关于如何在不检查依赖项是否下载的情况下获取 ivy:cachepath 位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆