You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-user@ant.apache.org by Fred Vos <fr...@fredvos.org> on 2007/05/07 22:12:17 UTC

Read from Maven local repository

Hello,

I'm completely new to Ivy. At the moment I'm using Maven to build my
software. Now I'm trying to collect dependencies automatically in the
target/lib directory using Ivy 1.4.1 on the command line. Later I want to
fetch my jars from within a Java program. I want Ivy to fetch the jars from my
local Maven repository at ~/.m2/repository only. How do I setup my
ivysettings.xml for that?

Here's my ivy.xml file:

<?xml version="1.0"?>
<ivy-module version="1.0">
  <info organisation="org" module="standalone" revision="working"/>
  <dependencies>
    <dependency org="xom" name="xom" rev="1.1" conf="default->*"/>
    <dependency org="com.martiansoftware" name="jsap" rev="2.1"
    conf="default->*"/>
  </dependencies>
</ivy-module>

and my ivysettings.xml file:

<?xml version="1.0"?>
<ivysettings>
  <property name="local-maven2-pattern"
  value="file:${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].[ext]" override="false" />
  <resolvers>
    <url name="local-maven2" m2compatible="true">
      <artifact pattern="${local-maven2-pattern}"/>
    </url>
  </resolvers>
</ivysettings>

When I do

% java -cp <classpath> fr.jayasoft.ivy.Main

it tries to download xom from an external repository (successfull) and jsap
(not successfull). But this is not what I want. I already have both xom and
jsap and all their dependencies in my local maven repository and want to use
that repository.

When I do

% java -cp <classpath> fr.jayasoft.ivy.Main -conf ivysettings.xml

it complains for both xom and jsap that it cannot find a resolver:

:: [ xom | xom | 1.1 ]: no resolver found for [ xom | xom ]: check your
configuration

So I guess something is wrong with my ivysettings.xml file. Can someone help
me with this first step?

Thanks,

Fred

-- 
|E  R
| D  F
|
|fred at fredvos dot org
|5235 DG 52 NL +31 73 6411833

Re: Read from Maven local repository

Posted by Fred Vos <fr...@fredvos.org>.
On Wed, May 09, 2007 at 11:24:31PM +0200, Xavier Hanin wrote:
> First, could you please subscribe to the list, your messages are moderated
> each time.

You're right and I'm sorry. I subscribed.

> You can use even -debug if verbose is not enough. The reason is usually that
> Ivy doesn't find appropriate metadata. It may happen that this is only
> cache's fault, so clean your cache and try again. If you still have trouble,
> check your ivy cache after a resolve, and check the ivy file generated by
> ivy for your dependencies. If they you see a default="true" attribute Ivy
> has not found your pom. The debug log at least should tell which attempts
> Ivy does.
> 
> One thing I think about, since you are using poms with an url resolver, it's
> a good idea to tell ivy to use pom as extension. Replace your ivy pattern by
> this one:
> <ivy pattern="file:${user.home
> }/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].pom
> "/>

This is the solution! With this small change I get all my dependencies.

> 
> Last, I recommend using a file system resolver instead of an url one when
> using file based repository. It allows to get revision listings.

Ok, I changed that and got it working too with this filesystem resolver.

Now I can try to solve a circular dependency. The transitive dependencies of
xom 1.1 make an excellent example of horrific dependencies in Maven repo1. I
don't think I need help solving this. Thank you Xavier. These are my files now:

ivysetings.xml
--------------
<?xml version="1.0"?>
<settings defaultResolver="local-maven2">
  <property name="local-maven2-pattern"
  value="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].pom" override="false" />
  <resolvers>
    <filesystem name="local-maven2" m2compatible="true">
      <ivy pattern="${local-maven2-pattern}"/>
      <artifact pattern="${local-maven2-pattern}"/>
    </filesystem>
  </resolvers>
</settings>

ivy.xml
-------
<?xml version="1.0"?>
<ivy-module version="1.0">
  <info organisation="org" module="standalone" revision="working"/>
  <dependencies>
    <dependency org="xom" name="xom" rev="1.1" conf="default->*"/>
    <dependency org="com.martiansoftware" name="jsap" rev="2.1"
    conf="default->*"/>
  </dependencies>
</ivy-module>

The command I used to fill the target/lib directory with all dependencies:

java -cp <classpath> org.apache.ivy.Main -settings ivysettings.xml -retrieve "target/lib/[artifact]-[revision].[ext]" 
(using ivy-2.0.0-alpha-1, Sun Java 1.6.0)

%ls -1 target/lib
dom4j-1.6.1.jar
jaxen-1.1-beta-8.jar
jdom-1.0.jar
jsap-2.1.jar
xalan-2.7.0.jar
xercesImpl-2.6.2.jar
xml-apis-2.0.2.jar
xmlParserAPIs-2.6.2.jar
xom-1.1.jar

Fred

Re: Read from Maven local repository

Posted by Xavier Hanin <xa...@gmail.com>.
First, could you please subscribe to the list, your messages are moderated
each time.

On 5/9/07, Fred Vos <fr...@fredvos.org> wrote:
>
> On Wed, May 09, 2007 at 01:18:24AM +0200, Xavier Hanin wrote:
> > On 5/8/07, Fred Vos <fr...@fredvos.org> wrote:
> [...]
> >
> > To get transitive dependencies Ivy need to get metadata about your
> modules,
> > so you have to configure your url resolver to tell where your module
> > descriptors (poms in your case) are. The name is misleading, but what
> you
> > actually need to do is add an ivy pattern to your url resolver:
> >   <url name="local-maven2" m2compatible="true">
> >     <ivy pattern="${local-maven2-pattern}"/>
> >     <artifact pattern="${local-maven2-pattern}"/>
> >   </url>
>
> I added this <ivy pattern line.
>
> >
> > and how to put all dependencies in the
> > >target/lib directory.
> >
> >
> > This is what the retrieve operation is for, you should have something
> like
> > that on the command line (if there isn't, open a JIRA issue).
>
> There is a retrieve operation in the command line. I used this command:
>
> % java -cp <classpath> -settings ivysettings.xml -retrieve
> "target/lib/[artifact]-[revision].[ext]"
>
> This does create a target/lib subdirectory and adds the two direct
> dependencies to this lib directory. That's a big step forward.
> Unfortunately
> it doesn't add the transitive dependencies. I don't see any warnings or
> errors. I tried adding a transitive="true" attribute to both dependencies
> in
> the ivy.xml file, but that doesn't help. Running the command with -verbose
> flag doesn't reveal any problem. Searched google to for any other clue,
> but
> couldn't find anythying.


You can use even -debug if verbose is not enough. The reason is usually that
Ivy doesn't find appropriate metadata. It may happen that this is only
cache's fault, so clean your cache and try again. If you still have trouble,
check your ivy cache after a resolve, and check the ivy file generated by
ivy for your dependencies. If they you see a default="true" attribute Ivy
has not found your pom. The debug log at least should tell which attempts
Ivy does.

One thing I think about, since you are using poms with an url resolver, it's
a good idea to tell ivy to use pom as extension. Replace your ivy pattern by
this one:
<ivy pattern="file:${user.home
}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].pom
"/>

Last, I recommend using a file system resolver instead of an url one when
using file based repository. It allows to get revision listings.

HTH,

Xavier

Puzzled,
>
> Fred
>
> --
> |E  R
> | D  F
> |
> |fred at fredvos dot org
> |5235 DG 52 NL +31 73 6411833
>



-- 
Xavier Hanin - Independent Java Consultant
Manage your dependencies with Ivy!
http://incubator.apache.org/ivy/

Re: Read from Maven local repository

Posted by Fred Vos <fr...@fredvos.org>.
On Wed, May 09, 2007 at 01:18:24AM +0200, Xavier Hanin wrote:
> On 5/8/07, Fred Vos <fr...@fredvos.org> wrote:
[...]
> 
> To get transitive dependencies Ivy need to get metadata about your modules,
> so you have to configure your url resolver to tell where your module
> descriptors (poms in your case) are. The name is misleading, but what you
> actually need to do is add an ivy pattern to your url resolver:
>   <url name="local-maven2" m2compatible="true">
>     <ivy pattern="${local-maven2-pattern}"/>
>     <artifact pattern="${local-maven2-pattern}"/>
>   </url>

I added this <ivy pattern line.

> 
> and how to put all dependencies in the
> >target/lib directory.
> 
> 
> This is what the retrieve operation is for, you should have something like
> that on the command line (if there isn't, open a JIRA issue).

There is a retrieve operation in the command line. I used this command:

% java -cp <classpath> -settings ivysettings.xml -retrieve "target/lib/[artifact]-[revision].[ext]"

This does create a target/lib subdirectory and adds the two direct
dependencies to this lib directory. That's a big step forward. Unfortunately
it doesn't add the transitive dependencies. I don't see any warnings or
errors. I tried adding a transitive="true" attribute to both dependencies in
the ivy.xml file, but that doesn't help. Running the command with -verbose
flag doesn't reveal any problem. Searched google to for any other clue, but
couldn't find anythying.

Puzzled,

Fred

-- 
|E  R
| D  F
|
|fred at fredvos dot org
|5235 DG 52 NL +31 73 6411833

Re: Read from Maven local repository

Posted by Xavier Hanin <xa...@gmail.com>.
On 5/8/07, Fred Vos <fr...@fredvos.org> wrote:
>
> Hello Xavier,
>
> On Tue, May 08, 2007 at 05:37:15PM +0200, Xavier Hanin wrote:
> > Hi,
> >
> > First if you use the 1.4 version, the settings file was called
> > configuration file and not settings file. This is important because
> > the tags used in the file have changed too. So make sure to use the
> > 1.4 documentation and not doc from the web site if you use 1.4. OTOH,
> > if you plan to use maven compatiblity as you seem to be, I'd recommend
> > using 2.0 alpha 1, in which we have fixed some bugs related to pom
> > parsing.
>
> I downloaded this 2.0 alpha 1.
>
> >
> > So now for your settings. First I'm surprised that at your first
> > attempt Ivy tries to download files from a remote repository. Maybe it
> > hasn't loaded your settings at all. Check your console output to make
> > sure of which settings is used.
> >
> > Your second problem is related to the fact that you do not define a
> > default resolver, so Ivy doesn't know which resolver to use to resolve
> > your dependencies (even if with only one resolver Ivy could make a
> > pretty good guess :-)). So you need to add this line:
> > <settings defaultResolver="local-maven2" />
> > or
> > <conf defaultResolver="local-maven2" />
> > for Ivy 1.4.
> >
>
> These are my files now:
>
> ivy.xml
> -------
> <?xml version="1.0"?>
> <ivy-module version="1.0">
>   <info organisation="org" module="standalone" revision="working"/>
>   <dependencies>
>     <dependency org="xom" name="xom" rev="1.1" conf="default->*"/>
>     <dependency org="com.martiansoftware" name="jsap" rev="2.1"
>     conf="default->*"/>
>   </dependencies>
> </ivy-module>
>
> ivysettings.xml
> ---------------
> <?xml version="1.0"?>
> <settings defaultResolver="local-maven2">
>   <property name="local-maven2-pattern"
>   value="file:${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].[ext]"
> override="false" />
>   <resolvers>
>     <url name="local-maven2" m2compatible="true">
>       <artifact pattern="${local-maven2-pattern}"/>
>     </url>
>   </resolvers>
> </settings>
>
> After removing my ~/.ivy directory and
> % java -cp <classpath> org.apache.ivy.Main -settings ivysettings.xml
>
> everything works fine! Ivy copies these two dependencies from my local
> maven
> repository into its cache.
>
> Thank you, Xavier, for your quick help. Now I can try to find out how to
> make
> Ivy get the cascading dependencies too


To get transitive dependencies Ivy need to get metadata about your modules,
so you have to configure your url resolver to tell where your module
descriptors (poms in your case) are. The name is misleading, but what you
actually need to do is add an ivy pattern to your url resolver:
   <url name="local-maven2" m2compatible="true">
     <ivy pattern="${local-maven2-pattern}"/>
     <artifact pattern="${local-maven2-pattern}"/>
   </url>

and how to put all dependencies in the
> target/lib directory.


This is what the retrieve operation is for, you should have something like
that on the command line (if there isn't, open a JIRA issue).

Xavier

You mentioned the difference between the old and new
> documentation. I guess this will help me find the info I need.
>
> Thanks again,
>
> Fred
>
> >
> > On 5/7/07, Fred Vos <fr...@fredvos.org> wrote:
> > >Hello,
> > >
> > >I'm completely new to Ivy. At the moment I'm using Maven to build my
> > >software. Now I'm trying to collect dependencies automatically in the
> > >target/lib directory using Ivy 1.4.1 on the command line. Later I want
> to
> > >fetch my jars from within a Java program. I want Ivy to fetch the jars
> > >from my
> > >local Maven repository at ~/.m2/repository only. How do I setup my
> > >ivysettings.xml for that?
> > >
> > >Here's my ivy.xml file:
> > >
> > ><?xml version="1.0"?>
> > ><ivy-module version="1.0">
> > >  <info organisation="org" module="standalone" revision="working"/>
> > >  <dependencies>
> > >    <dependency org="xom" name="xom" rev="1.1" conf="default->*"/>
> > >    <dependency org="com.martiansoftware" name="jsap" rev="2.1"
> > >    conf="default->*"/>
> > >  </dependencies>
> > ></ivy-module>
> > >
> > >and my ivysettings.xml file:
> > >
> > ><?xml version="1.0"?>
> > ><ivysettings>
> > >  <property name="local-maven2-pattern"
> > >  value="file:${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].[ext]"
> override="false" />
> > >  <resolvers>
> > >    <url name="local-maven2" m2compatible="true">
> > >      <artifact pattern="${local-maven2-pattern}"/>
> > >    </url>
> > >  </resolvers>
> > ></ivysettings>
> > >
> > >When I do
> > >
> > >% java -cp <classpath> fr.jayasoft.ivy.Main
> > >
> > >it tries to download xom from an external repository (successfull) and
> jsap
> > >(not successfull). But this is not what I want. I already have both xom
> and
> > >jsap and all their dependencies in my local maven repository and want
> to
> > >use
> > >that repository.
> > >
> > >When I do
> > >
> > >% java -cp <classpath> fr.jayasoft.ivy.Main -conf ivysettings.xml
> > >
> > >it complains for both xom and jsap that it cannot find a resolver:
> > >
> > >:: [ xom | xom | 1.1 ]: no resolver found for [ xom | xom ]: check your
> > >configuration
> > >
> > >So I guess something is wrong with my ivysettings.xml file. Can someone
> > >help
> > >me with this first step?
> > >
> > >Thanks,
> > >
> > >Fred
> > >
> > >--
> > >|E  R
> > >| D  F
> > >|
> > >|fred at fredvos dot org
> > >|5235 DG 52 NL +31 73 6411833
> > >
> >
> >
> > --
> > Xavier Hanin - Independent Java Consultant
> > Manage your dependencies with Ivy!
> > http://incubator.apache.org/ivy/
>
> --
> |E  R
> | D  F
> |
> |fred at fredvos dot org
> |5235 DG 52 NL +31 73 6411833
>



-- 
Xavier Hanin - Independent Java Consultant
Manage your dependencies with Ivy!
http://incubator.apache.org/ivy/

Re: Read from Maven local repository

Posted by Fred Vos <fr...@fredvos.org>.
Hello Xavier,

On Tue, May 08, 2007 at 05:37:15PM +0200, Xavier Hanin wrote:
> Hi,
> 
> First if you use the 1.4 version, the settings file was called
> configuration file and not settings file. This is important because
> the tags used in the file have changed too. So make sure to use the
> 1.4 documentation and not doc from the web site if you use 1.4. OTOH,
> if you plan to use maven compatiblity as you seem to be, I'd recommend
> using 2.0 alpha 1, in which we have fixed some bugs related to pom
> parsing.

I downloaded this 2.0 alpha 1.

> 
> So now for your settings. First I'm surprised that at your first
> attempt Ivy tries to download files from a remote repository. Maybe it
> hasn't loaded your settings at all. Check your console output to make
> sure of which settings is used.
> 
> Your second problem is related to the fact that you do not define a
> default resolver, so Ivy doesn't know which resolver to use to resolve
> your dependencies (even if with only one resolver Ivy could make a
> pretty good guess :-)). So you need to add this line:
> <settings defaultResolver="local-maven2" />
> or
> <conf defaultResolver="local-maven2" />
> for Ivy 1.4.
> 

These are my files now:

ivy.xml
-------
<?xml version="1.0"?>
<ivy-module version="1.0">
  <info organisation="org" module="standalone" revision="working"/>
  <dependencies>
    <dependency org="xom" name="xom" rev="1.1" conf="default->*"/>
    <dependency org="com.martiansoftware" name="jsap" rev="2.1"
    conf="default->*"/>
  </dependencies>
</ivy-module>

ivysettings.xml
---------------
<?xml version="1.0"?>
<settings defaultResolver="local-maven2">
  <property name="local-maven2-pattern"
  value="file:${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].[ext]" override="false" />
  <resolvers>
    <url name="local-maven2" m2compatible="true">
      <artifact pattern="${local-maven2-pattern}"/>
    </url>
  </resolvers>
</settings>

After removing my ~/.ivy directory and
% java -cp <classpath> org.apache.ivy.Main -settings ivysettings.xml

everything works fine! Ivy copies these two dependencies from my local maven
repository into its cache.

Thank you, Xavier, for your quick help. Now I can try to find out how to make
Ivy get the cascading dependencies too and how to put all dependencies in the
target/lib directory. You mentioned the difference between the old and new
documentation. I guess this will help me find the info I need.

Thanks again,

Fred

> 
> On 5/7/07, Fred Vos <fr...@fredvos.org> wrote:
> >Hello,
> >
> >I'm completely new to Ivy. At the moment I'm using Maven to build my
> >software. Now I'm trying to collect dependencies automatically in the
> >target/lib directory using Ivy 1.4.1 on the command line. Later I want to
> >fetch my jars from within a Java program. I want Ivy to fetch the jars 
> >from my
> >local Maven repository at ~/.m2/repository only. How do I setup my
> >ivysettings.xml for that?
> >
> >Here's my ivy.xml file:
> >
> ><?xml version="1.0"?>
> ><ivy-module version="1.0">
> >  <info organisation="org" module="standalone" revision="working"/>
> >  <dependencies>
> >    <dependency org="xom" name="xom" rev="1.1" conf="default->*"/>
> >    <dependency org="com.martiansoftware" name="jsap" rev="2.1"
> >    conf="default->*"/>
> >  </dependencies>
> ></ivy-module>
> >
> >and my ivysettings.xml file:
> >
> ><?xml version="1.0"?>
> ><ivysettings>
> >  <property name="local-maven2-pattern"
> >  value="file:${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].[ext]" override="false" />
> >  <resolvers>
> >    <url name="local-maven2" m2compatible="true">
> >      <artifact pattern="${local-maven2-pattern}"/>
> >    </url>
> >  </resolvers>
> ></ivysettings>
> >
> >When I do
> >
> >% java -cp <classpath> fr.jayasoft.ivy.Main
> >
> >it tries to download xom from an external repository (successfull) and jsap
> >(not successfull). But this is not what I want. I already have both xom and
> >jsap and all their dependencies in my local maven repository and want to 
> >use
> >that repository.
> >
> >When I do
> >
> >% java -cp <classpath> fr.jayasoft.ivy.Main -conf ivysettings.xml
> >
> >it complains for both xom and jsap that it cannot find a resolver:
> >
> >:: [ xom | xom | 1.1 ]: no resolver found for [ xom | xom ]: check your
> >configuration
> >
> >So I guess something is wrong with my ivysettings.xml file. Can someone 
> >help
> >me with this first step?
> >
> >Thanks,
> >
> >Fred
> >
> >--
> >|E  R
> >| D  F
> >|
> >|fred at fredvos dot org
> >|5235 DG 52 NL +31 73 6411833
> >
> 
> 
> -- 
> Xavier Hanin - Independent Java Consultant
> Manage your dependencies with Ivy!
> http://incubator.apache.org/ivy/

-- 
|E  R
| D  F
|
|fred at fredvos dot org
|5235 DG 52 NL +31 73 6411833

Re: Read from Maven local repository

Posted by Xavier Hanin <xa...@gmail.com>.
Hi,

First if you use the 1.4 version, the settings file was called
configuration file and not settings file. This is important because
the tags used in the file have changed too. So make sure to use the
1.4 documentation and not doc from the web site if you use 1.4. OTOH,
if you plan to use maven compatiblity as you seem to be, I'd recommend
using 2.0 alpha 1, in which we have fixed some bugs related to pom
parsing.

So now for your settings. First I'm surprised that at your first
attempt Ivy tries to download files from a remote repository. Maybe it
hasn't loaded your settings at all. Check your console output to make
sure of which settings is used.

Your second problem is related to the fact that you do not define a
default resolver, so Ivy doesn't know which resolver to use to resolve
your dependencies (even if with only one resolver Ivy could make a
pretty good guess :-)). So you need to add this line:
<settings defaultResolver="local-maven2" />
or
<conf defaultResolver="local-maven2" />
for Ivy 1.4.

HTH,

Xavier


On 5/7/07, Fred Vos <fr...@fredvos.org> wrote:
> Hello,
>
> I'm completely new to Ivy. At the moment I'm using Maven to build my
> software. Now I'm trying to collect dependencies automatically in the
> target/lib directory using Ivy 1.4.1 on the command line. Later I want to
> fetch my jars from within a Java program. I want Ivy to fetch the jars from my
> local Maven repository at ~/.m2/repository only. How do I setup my
> ivysettings.xml for that?
>
> Here's my ivy.xml file:
>
> <?xml version="1.0"?>
> <ivy-module version="1.0">
>   <info organisation="org" module="standalone" revision="working"/>
>   <dependencies>
>     <dependency org="xom" name="xom" rev="1.1" conf="default->*"/>
>     <dependency org="com.martiansoftware" name="jsap" rev="2.1"
>     conf="default->*"/>
>   </dependencies>
> </ivy-module>
>
> and my ivysettings.xml file:
>
> <?xml version="1.0"?>
> <ivysettings>
>   <property name="local-maven2-pattern"
>   value="file:${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision].[ext]" override="false" />
>   <resolvers>
>     <url name="local-maven2" m2compatible="true">
>       <artifact pattern="${local-maven2-pattern}"/>
>     </url>
>   </resolvers>
> </ivysettings>
>
> When I do
>
> % java -cp <classpath> fr.jayasoft.ivy.Main
>
> it tries to download xom from an external repository (successfull) and jsap
> (not successfull). But this is not what I want. I already have both xom and
> jsap and all their dependencies in my local maven repository and want to use
> that repository.
>
> When I do
>
> % java -cp <classpath> fr.jayasoft.ivy.Main -conf ivysettings.xml
>
> it complains for both xom and jsap that it cannot find a resolver:
>
> :: [ xom | xom | 1.1 ]: no resolver found for [ xom | xom ]: check your
> configuration
>
> So I guess something is wrong with my ivysettings.xml file. Can someone help
> me with this first step?
>
> Thanks,
>
> Fred
>
> --
> |E  R
> | D  F
> |
> |fred at fredvos dot org
> |5235 DG 52 NL +31 73 6411833
>


-- 
Xavier Hanin - Independent Java Consultant
Manage your dependencies with Ivy!
http://incubator.apache.org/ivy/