问题
I am trying to include jersey-servlet in my project using ivy. My dependency looks like this:
<dependency org="com.sun.jersey" name="jersey-servlet" rev="${jersey.version}"/>
...but I am running into some unresolved dependencies:
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve] :: UNRESOLVED DEPENDENCIES ::
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve] :: org.eclipse.persistence#org.eclipse.persistence.moxy;2.3.2: not found
[ivy:resolve] :: org.jboss.spec.javax.interceptor#jboss-interceptors-api_1.1_spec;${interceptor.api.version}: not found
[ivy:resolve] :: javax.inject#javax.inject;${atinject.api.version}: not found
[ivy:resolve] :: org.jboss.weld#weld-api;1.1.4.Final: not found
[ivy:resolve] :: org.jboss.weld#weld-spi;1.1.4.Final: not found
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
My research tells me weld-spi/api 1.1.4.Final do not exist. It looks like these are dependencies of weld-osgi-bundle-1.1.4.Final.jar. But if you open that jar and dig around inside the META-INF directory, there are references to weld-spi/api 1.1.Final, which DO exist.
Plus, in the maven repository, the dependencies table for weld-osgi-bundle 1.1.4.Final shows nothing in the version column.
Could it be that ivy is defaulting to the 1.1.4.Final version of the weld-osgi-bundle for all of its dependencies, whereas maven knows where to find the correct versions of the dependencies?
Is there a way around this with ivy?
==> Updating with now working ivy.xml, based on Eyads comments:
ivy.xml has the following dependencies:
<dependency org="com.sun.jersey" name="jersey-servlet" rev="${jersey.version}" transitive="false"/>
<dependency org="org.jboss.weld" name="weld-api" rev="1.1.Final" force="true"/>
Note, I also needed to add the eclipselink repo to get past the moxy dependency:
<ibiblio
name="eclipselink"
m2compatible="true"
root="http://download.eclipse.org/rt/eclipselink/maven.repo"
/>
回答1:
try to include that dependency with the version you want with 'force=true' in the dependency tag. I'm not sure if I got it completely right but this last dependency is not explicitly declared in your ivy.xml file, therefore you could add it explicitly and for the one that that you have, namely:
<dependency org="com.sun.jersey" name="jersey-servlet" rev="${jersey.version}" transitive="false" />
Notice the transitive attribute in the dependency tag.
This will prevent it from bringing the dependency that it wants (apparently the weld-api).
==============
UPDATE:
We have now the same problem in my company but for a different reason. we were trying to include another dependency
<dependency org="org.jboss.weld.se" name="weld-se-core" rev="1.1.8.Final" />
This will try to retrieve weld-api and weld-spi with revision of 1.1.8.Final. The reason we came to see, was that in maven pom they have an "import" tag for their parent dependency which depends on another parent pom (in a nutshell).
So Ivy doesn't know how to deal with it and it uses the current version 1.1.8.Final instead of the one that declares 1.1.Final for the api and spi.
You either resolve IVY and delete one the folder org.jboss.weld.se from cache but keep org.jboss.weld in it, and then resolve again.
Or you could add those:
<dependency org="org.jboss.weld" name="weld-spi" rev="1.1.Final" force="true"/>
<dependency org="org.jboss.weld" name="weld-api" rev="1.1.Final" force="true"/>
right above the original dependency.
If you put it afterwards it will still fail to override the version.
回答2:
It's a bug https://issues.apache.org/jira/browse/IVY-1376. So a solution can be: wait for a fix and vote the bug up while waiting.
来源:https://stackoverflow.com/questions/11712720/ivy-2-3-cant-resolve-dependencies-for-jersey-servlet-1-13-or-1-11-or-1-12