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

问题描述

我的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.

是否有一种方法可以从常春藤获取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":

第二,您在串联模式下使用常春藤,大概是为了避免创建是文件?常春藤缓存路径被分类为后解析任务,这意味着它将自动调用解决任务在后台运行.内联模式的作用是让常春藤每次执行一次新的解析,如果您要管理多个类路径,这将很浪费.

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.

最后,您考虑过使用常春藤文件吗?只需调用解决任务即可所有项目的依赖项,在本地缓存此信息,然后确定是否需要下载文件.我建议始终解决依赖关系.花费不多,而且构建之间的情况可能已发生变化(例如,如果您使用的是动态依赖项或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 任务正在使用常春藤配置,以对常春藤文件中的依赖项进行分组或分类.这确实是提高效率的魔力,它可以节省单个分辨率的时间.
  • 注意 install-ivy 任务如何进行条件检查以确定是否安装了ivy.由于复杂性,此技巧与项目的其余依赖项不可行.我的建议是确保常春藤存在,然后使用它来管理其他所有事物. (在引擎盖下,它将尽最大努力提高效率).我真的不明白为什么Apache Ant不会捆绑常春藤罐子.
  • 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位置,而不检查是否下载了依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 23:05