Adem İlhan
Adem İlhan

Reputation: 1500

ivy doesn't download jar from remote after local

I configured ivy to go first maven local repo then remote. But something is going wrong! (By the way, im working with snapshots)

  1. If ivy cache doesn't exist, ivy first checks maven local repo and then remote to get required jars. Everything is fine.
  2. If ivy cache exists, ivy just checks local repo! It doesn't check remote! I have 2 problem here:
    • If I change something in maven project and install it to local repo of maven, ivy still gets the jar from its cache, not in local repo of maven.
    • Even worse, it doesn't get any jar in remote if requsted jars in ivy cache.

ivysettings.xml

<ivysettings>
  <settings defaultResolver="chain_resolver"/>

  <credentials host="localhost"
               realm="Sonatype Nexus Repository Manager"
               username="username" passwd="password"/>

  <property name="nexus.repo" value="url here"/>
  <property name="nexus-public" value="http://${nexus.repo}:8081/nexus/content/groups/public"/>
  <property name="m2-pattern"   value="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]"/>

  <resolvers>
    <chain name="chain_resolver">
      <ibiblio name="nexus" m2compatible="true" root="${nexus-public}"/>
      <filesystem name="local" m2compatible="true">
        <artifact pattern="${m2-pattern}"/>
        <ivy pattern="${m2-pattern}"/>
      </filesystem>
    </chain>
  </resolvers>

</ivysettings>

Related ant tasks

<target name="ivy-download" unless="offline">
    <mkdir dir="${ivy.dir}"/>
    <get src="${repo_public}/org/apache/ivy/ivy/${ivy.ver}/ivy-${ivy.ver}.jar" dest="${ivy.jar}" usetimestamp="true"/>
  </target>

  <target name="ivy-install" depends="ivy-download">
    <path id="ivy.lib.path">
      <fileset file="${ivy.jar}"/>
    </path>
    <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
    <ivy:settings file="ivysettings.xml" />
  </target>

  <target name="lib.get">
    <mkdir dir="${lib.dir}"/>
    <ivy:retrieve type="jar" conf="lib" pattern="${lib.dir}/[artifact]-[revision].[ext]"/>
  </target>

  <target name="ivy.lib.get" depends="ivy-install" if="${skipClean}">
      <antcall target="lib.get" />
    </target>

  <target name="ivy.clean.lib.get" depends="ivy-install" unless="${skipClean}">
    <ivy:cleancache/>
    <antcall target="lib.get" />
  </target>

How can I check

And there is one more possible situation here which is, if there is a change in remote and local at the same time, what should I do?

Upvotes: 2

Views: 1685

Answers (1)

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 77991

Ivy has a local cache dedicated to that purpose. Improving performance by avoiding repeated download of the same artifact. Maven, on the other hand, uses its local repository as a cache (Ivy keeps these concepts separate).

The one operational problem with caches is that over time they become dirty, especially when sharing "integration" or "snapshot" builds.

For this reason I suggest you stop pointing ivy at the Maven local cache for the following reasons:

  1. You're creating a strong dependency between two different build technologies.
  2. You're caching a cache, rather than caching a repository.... It's a false economy, due to the risk of dirty caches.

My suggestion is simplify everything by introducing a Maven repository manager like Nexus, in order to both cache files from Maven Central and host artifacts shared between project builds.

Upvotes: 0

Related Questions