14

How can I get Ivy to resolve dependencies (including dependencies with changing="true") from the local cache when offline/disconnected?

I'm working on a Java-based open-source project that uses Apache Ivy to resolve and download 3rd party dependencies. The project's build.xml has an ant target named resolve that downloads Ivy (if needed) and then uses Ivy to retrieve the required jars.

Everything works great when online. However, without Internet access, ant resolve fails even if the required jars are in the local Ivy cache (~/.ivy2/cache). It appears that Ivy is trying to connect to the Maven repository to refresh changing="true" dependencies.

The error I get is similar to the following:

[ivy:retrieve] You probably access the destination server through a proxy server that is not well configured.
[ivy:retrieve] You probably access the destination server through a proxy server that is not well configured.
[ivy:retrieve] 
[ivy:retrieve] :: problems summary ::
[ivy:retrieve] :::: WARNINGS
[ivy:retrieve]  Host repo.example.com not found. url=http://repo.example.com/exampleorg/examplename/examplerev/ivys/ivy.xml
[ivy:retrieve]  Host repo.example.com not found. url=http://repo.example.com/exampleorg/examplename/examplerev/jars/examplename.jar
[ivy:retrieve]          module not found: exampleorg#examplename;examplerev
[ivy:retrieve]  ==== local: tried
[ivy:retrieve]    ~/.ivy2/local/exampleorg/examplename/examplerev/ivys/ivy.xml
[ivy:retrieve]    -- artifact exampleorg#examplename;examplerev!examplename.jar:
[ivy:retrieve]    ~/.ivy2/local/exampleorg/examplename/examplerev/jars/examplename.jar
[ivy:retrieve]  ==== shared: tried
[ivy:retrieve]    ~/.ivy2/shared/exampleorg/examplename/examplerev/ivys/ivy.xml
[ivy:retrieve]    -- artifact exampleorg#examplename;examplerev!examplename.jar:
[ivy:retrieve]    ~/.ivy2/shared/exampleorg/examplename/examplerev/jars/examplename.jar
[ivy:retrieve]  ==== repo: tried
[ivy:retrieve]    http://repo.example.com/exampleorg/examplename/examplerev/ivys/ivy.xml
[ivy:retrieve]    -- artifact exampleorg#examplename;examplerev!examplename.jar:
[ivy:retrieve]    http://repo.example.com/exampleorg/examplename/examplerev/jars/examplename.jar
[ivy:retrieve]          ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]          ::          UNRESOLVED DEPENDENCIES         ::
[ivy:retrieve]          ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]          :: exampleorg#examplename;examplerev: not found
[ivy:retrieve]          ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve] 
[ivy:retrieve] :: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS

BUILD FAILED
~/exampleproj/build.xml:123: impossible to resolve dependencies:
        resolve failed - see output for details

Running ant -verbose resolve as suggested by the warning prints the following line in the output:

[ivy:retrieve] don't use cache for exampleorg#examplename;examplerev: changing=true

How can I get Ivy to resolve changing="true" dependencies from the cache when offline, but continue to query the repository each build when online?

Richard Hansen
  • 51,690
  • 20
  • 90
  • 97
  • 1
    I gave an answer to that in this question: http://stackoverflow.com/questions/6971517/how-do-i-tell-ivy4r-to-stay-offline – oers Mar 09 '12 at 07:14
  • That's a second question. The first one has been answered – Mark O'Connor Mar 11 '12 at 17:29
  • @Mark: You're right. I edited the question to remove the "how to conditionally set `ivy.cache.ttl.default=eternal`?" part because that is a separate issue. But my original question -- how to resolve dependencies when offline -- is still unanswered. – Richard Hansen Mar 12 '12 at 00:26
  • it sounds like changing and ttl cannot be used together, it might be a good idea to ask this question on the [mailing list](https://ant.apache.org/ivy/mailing-lists.html) – oers Mar 13 '12 at 07:27
  • This may be of interest: https://stackoverflow.com/questions/53622640/ivycachepath-is-slow-how-to-avoid-doing-it-every-build-and-improve-ivy-cache – Jonathan Dec 04 '18 at 23:38

1 Answers1

13

oers has answered the question, but it's not obvious.

Try running your build setting the ivy.cache.ttl.default property from the command-line:

ant -Divy.cache.ttl.default=eternal build

Sources:

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • I hope you don't mind, I updated my answer with some of the information you gave here, to improve it. – oers Mar 09 '12 at 12:40
  • Thanks for the answer. Unfortunately, `-Divy.cache.ttl.default=eternal` doesn't work for me. Please see the updated question. – Richard Hansen Mar 10 '12 at 05:31
  • @RichardHansen It looks like your build is not caching as expected...Could you post up your ivy settings? When I tested my ivy build it worked offline without any special settings :-( (Also what version of ivy are you using?) – Mark O'Connor Mar 10 '12 at 14:20
  • 2
    I figured out why `eternal` didn't work: the dependency was marked `changing="true"`. See updated question. – Richard Hansen Mar 10 '12 at 19:42