how to use the [ext] variable in ivy?

久未见 提交于 2019-12-24 09:16:45

问题


I want to use the url resolver to download depends. The depends are JS, or XML files. So, I used:

<url name="urlresolver">
  <artifact pattern="http://[organisation]/[module]-[revision].[ext]" />
</url>

And

<ivy:retrieve pattern="${build}/[module]-[revision].[ext]"/>

the file is saved in .jar extension.


回答1:


It's worth digging around the following ivy docs:

  • Terminology
  • Main Concepts
  • Best Practices

The first problem is that your url resolver is not configured to read ivy files for the remote modules (ignoring the first recommendation, in the ivy best practices, to use an ivy file with each module). Without module meta-data ivy will assume you're attempting to download JAR files.

A second problem is that you don't appear to be using an ivy repository to store your files. The following dependency declaration:

<dependency org="yourorg" name="module1" rev="9.1"/>

would be translated into the following URL, using your current settings:

http://yourorg/module1-9.1.jar

The "org" field is designed to specify the organisational unit publishing the module, not the server hostname.

I suspect that you're not really interested in building a repository of files and just want to persuade ivy to download and cache the files? In that case I'd recommend reading the following answer which is using extra attributes on the dependency artifacts to do something similar:

  • Resolving XSD's using Ivy

Example

ivy.xml

<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
    ..
    ..
    <dependency org="yourorg" name="yourmodule1" rev="9.1">
       <artifact name="file1"  e:hostname="www.server1.com" type="xml"/>
       <artifact name="file2"  e:hostname="www.server1.com" type="xml"/>
    </dependency>

    <dependency org="yourorg" name="yourmodule2" rev="9.1">
       <artifact name="file3"  e:hostname="www.server2.com" type="xml"/>
       <artifact name="file4"  e:hostname="www.server2.com" type="xml"/>
    </dependency>
    ..

Note:

  • Each dependency declares the type of each artifact, plus the additional "hostname" attribute.
  • If the remote modules had ivy.xml, the publications section would alternatively store this artifact information.
  • Extra artifacts demonstrate ivy's power in enabling any sort of custom attribute meta-data.

ivysettings.xml

..
<url name="urlresolver">
      <artifact pattern="http://[hostname]/files/[organisation]/[module]-[revision].[ext]" />
</url>
..

Demonstrates how the resolver makes use of both the standard attributes and the custom "hostname".



来源:https://stackoverflow.com/questions/12249926/how-to-use-the-ext-variable-in-ivy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!