Ivy cached a dependency file, but not copy to my l

2019-06-28 02:25发布

问题:

I got a strange problem. I added Guava to my ivy.xml as the following:

<dependency org="com.google.guava" name="guava" rev="14.0.1" conf="test"/>

When I run ant, I can see it's resolved:

[ivy:retrieve]  found com.google.guava#guava;14.0.1 in default

And I can find the file in the ~/.ivy2/cache. But it didn't get copied to my lib directory.

Other dependencies have no problem....Any advice? Thanks.

回答1:

Specify the configuration mapping in ivy.xml

I had the same problem and couldn't for the life of me figure out where the dependencies were downloaded to. Ivy seemed to suggest it was downloaded, and there were some entries in the cache, but nothing was appearing in my /lib.

---------------------------------------------------------------------
|                  |            modules            ||   artifacts   |
|       conf       | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
|      compile     |   2   |   2   |   2   |   0   ||   0   |   0   |
---------------------------------------------------------------------

But everything changed when I saw this answer.

In ivy.xml, you have to specify the configuration mapping conf="myconfig->default", the key being ->default

<configurations>
    <conf name="myconfig" description="Required for JSF"/>
</configurations>

<dependencies>
    <dependency conf="myconfig->default" name="jsf-api" org="com.sun.faces" rev="2.2.13"/>          
</dependencies>

This will map your user-defined configuration to a Maven scope (to be exact, the default scope). In practice, you will only use either default or master scope (source).

See:

  • Official description: http://ant.apache.org/ivy/history/2.2.0/ivyfile/configurations.html
  • IMHO a clearer explanation: http://wrongnotes.blogspot.sg/2014/02/simplest-explanation-of-ivy.html
  • This answer discusses maven scopes other than default: https://stackoverflow.com/a/7116577/4212710

My gut feel is that this is only required if you are pointing to an Maven repository. I have not tried otherwise.

If you have already done this and it still does not download, perhaps @javabrett's answer can help.



回答2:

If you truly used <ivy:retrieve />, not just resolve, then it's probably because you need to use conf="test->default" ?



回答3:

This is caused by the Maven packaging-type for com.google.guava:guava:14.0.1 being the OSGi bundle rather than jar. There is an Ivy bug for this that has been resolved, but the solution is not complete.

You need to avoid specifying type="jar" and instead use type="jar,bundle" if you want to download both package-types.

See also this question and the POM definition.



标签: ant guava ivy