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 "Brown, Carlton" <Ca...@compucredit.com> on 2008/03/27 20:34:37 UTC

How to specify which resolver to use at resolve time?

The publish and install tasks allow me to specify which resolver to use
for publishing (or installing).   I don't see this capability for the
resolve task, however.   Have I missed something?  If it isn't possible
to specify a resolver for the resolve task, that means I have to rely on
defaultResolver in ivy-settings.xml ?   Is there no way to control this
from within the Ant script, or must I maintain multiple copies of
ivy-settings.xml just to choose which resolver to use?



-----------------------------------------
====================================================
This message contains PRIVILEGED and CONFIDENTIAL
information that is intended only for use by the 
named recipient. If you are not the named recipient,
any disclosure, dissemination, or action based on 
the contents of this message is prohibited. In such
case please notify us and destroy and delete all 
copies of this transmission.  Thank you.
====================================================

RE: How to specify which resolver to use at resolve time?

Posted by antd <an...@gmail.com>.
Hi again,

After trying to implement a workaround, I've realized that specifying
"resolver" in resolve task isn't quite what I wanted. Specifying "resolver"
would imply only using that resolver in order to resolve dependencies. If
that were the case many errors would pop up as part of the resolution would
be unsuccessful since the rest of the dependencies are in other resolvers!

So what I really wanted was the "meta-data" of which resolver had the
artifact, and to use that in order to create a lib directory structure to
split them by resolver. One way that might be accomplished would be to have
another Ivy pattern called [resolver]. Then anyone can use the [resolver] as
part of the way they organize their directory structure during a retrieve
for example.

Having said all that, I came up with a workaround I'd like to share, but
it's a bit messy (which is why the above would make things so much simpler).

There are two main things you need to do:
1) Alter your ivysettings.xml to specify a different cache location for each
resolver you have. For example:

	<property name="ivysettings.first-party.cache.dir"
value="${user.home}/.ivy2/first-party-cache" override="false"/>
	<property name="ivysettings.third-party.cache.dir"
value="${user.home}/.ivy2/third-party-cache" override="false"/>

...

	<caches resolutionCacheDir="${user.home}/.ivy2/cache"  >
		<cache name="first-party-cache"
basedir="${ivysettings.first-party.cache.dir}" />
		<cache name="third-party-cache"
basedir="${ivysettings.third-party.cache.dir}" />
	</caches>

...

	<resolvers>
		<chain name="chained" returnFirst="true">
			<url name="first-party-releases" cache="first-party-cache">
...
			</url>
			<url name="third-party-releases" cache="third-party-cache">
...
			</url>
		</chain>
	</resolvers>


2) Then in your Ant build script, you use a pattern match to identify which
artifacts came from which cache based on the path:

		<ivy:cachepath pathid="lib.path.id" />
		<echo message="lib.path.id = ${toString:lib.path.id}" />

		<!-- 
			Identify first-party artifacts from the Ivy cachepath and copy
			them to the lib.build.dir directory.
		-->
		<copy todir="${lib.build.dir}">
			<path refid="lib.path.id" />
			<regexpmapper from="^.*/first-party-cache/.*/(.*)" to="\1"
handledirsep="true"/>
		</copy>



I hope that helps someone in a similar situation. If you think it's worth
having the [resolver] pattern/meta-data when doing a resolve, I can add a
defect/enhancement request.

Cheers.


antd wrote:
> 
> Hi,
> 
> I know this is an old thread, but I also tend to think it would be a nice
> feature to have to avoid complexity of multiple settings files. The
> alternative of using a property in the ivysettings file won't work easily
> for me because in the same common build script I use for all my projects,
> I want to use the default resolver and switch between the two I have as
> well.
> 
> Here is my use-case:
> - I use Hudson to build my Ivy-enabled ant scripts
> - I have several projects that dependent on other projects and also
> third-party libraries
> - I use Hudson fingerprinting (which basically records a unique identifier
> for build artifacts you specify) so that Hudson (and thus the user) knows
> what jar versions of Project B, C and D were used to build Project A
> - Hudson fingerprints are specified via a multiple directories (including
> wild cards)
> - All of my dependent jars (both first and third-party) resolve and
> retrieve to a folder called /lib
> 
> Thus is my dilemma. I cannot easily do a "fingerprint lib/*.jar" as it
> will end up fingerprinting all of the third-party libraries as well, which
> I don't want and is typically not done.
> 
> So long story short, if I could...
> - Ivy retrieve first-party dependencies to /lib/first-party
> - and Ivy retrieve third-party-dependencies to /lib/third-party
> ...it would be simple to specify lib/first-party/*.jar 
> 
> When you have many different first-party dependencies to specify, all with
> unique names, it gets error-prone in the Hudson fingerprint text box to
> type "lib/FirstDep.jar lib/SecondDep.jar lib/ThirdDep.jar etc." for every
> project you create.
> 
> In the meantime I'll try the workarounds suggested, but I think it would
> be very convenient to specify the resolver for all Ant/Ivy (post-)resolve
> tasks.
> 

-- 
View this message in context: http://old.nabble.com/How-to-specify-which-resolver-to-use-at-resolve-time--tp16338083p29521820.html
Sent from the ivy-user mailing list archive at Nabble.com.


RE: How to specify which resolver to use at resolve time?

Posted by antd <an...@gmail.com>.
Hi,

I know this is an old thread, but I also tend to think it would be a nice
feature to have to avoid complexity of multiple settings files. The
alternative of using a property in the ivysettings file won't work easily
for me because in the same common build script I use for all my projects, I
want to use the default resolver and switch between the two I have as well.

Here is my use-case:
- I use Hudson to build my Ivy-enabled ant scripts
- I have several projects that dependent on other projects and also
third-party libraries
- I use Hudson fingerprinting (which basically records a unique identifier
for build artifacts you specify) so that Hudson (and thus the user) knows
what jar versions of Project B, C and D were used to build Project A
- Hudson fingerprints are specified via a multiple directories (including
wild cards)
- All of my dependent jars (both first and third-party) resolve and retrieve
to a folder called /lib

Thus is my dilemma. I cannot easily do a "fingerprint lib/*.jar" as it will
end up fingerprinting all of the third-party libraries as well, which I
don't want and is typically not done.

So long story short, if I could...
- Ivy retrieve first-party dependencies to /lib/first-party
- and Ivy retrieve third-party-dependencies to /lib/third-party
...it would be simple to specify lib/first-party/*.jar 

When you have many different first-party dependencies to specify, all with
unique names, it gets error-prone in the Hudson fingerprint text box to type
"lib/FirstDep.jar lib/SecondDep.jar lib/ThirdDep.jar etc." for every project
you create.

In the meantime I'll try the workarounds suggested, but I think it would be
very convenient to specify the resolver for all Ant/Ivy (post-)resolve
tasks.

Cheers


Jim Adams-6 wrote:
> 
> Seems to me that the issue may be in the term "default resolver". Default
> implies that there is an override possible. In this case there is no
> override possible. Even if you say "use a property to specify the
> resolver" this is not really an override. Individual build scripts will
> have a hard time overriding. Plus you can't override to a different
> resolver in the same build since properties are immutable.

-- 
View this message in context: http://old.nabble.com/How-to-specify-which-resolver-to-use-at-resolve-time--tp16338083p29493552.html
Sent from the ivy-user mailing list archive at Nabble.com.


RE: How to specify which resolver to use at resolve time?

Posted by Jim Adams <Ji...@sas.com>.
Seems to me that the issue may be in the term "default resolver". Default implies that there is an override possible. In this case there is no override possible. Even if you say "use a property to specify the resolver" this is not really an override. Individual build scripts will have a hard time overriding. Plus you can't override to a different resolver in the same build since properties are immutable.

> -----Original Message-----
> From: Xavier Hanin [mailto:xavier.hanin@gmail.com]
> Sent: Friday, March 28, 2008 9:24 AM
> To: ivy-user@ant.apache.org
> Subject: Re: How to specify which resolver to use at resolve time?
>
> On Fri, Mar 28, 2008 at 1:54 PM, Brown, Carlton <
> Carlton.Brown@compucredit.com> wrote:
>
> > > -----Original Message-----
> > > From: Xavier Hanin [mailto:xavier.hanin@gmail.com]
> > > Sent: Friday, March 28, 2008 4:16 AM
> > > To: ivy-user@ant.apache.org
> > > Subject: Re: How to specify which resolver to use at resolve time?
> > >
> > > On Thu, Mar 27, 2008 at 8:34 PM, Brown, Carlton <
> > > Carlton.Brown@compucredit.com> wrote:
> > >
> > > > The publish and install tasks allow me to specify which
> > > resolver to use
> > > > for publishing (or installing).   I don't see this
> > > capability for the
> > > > resolve task, however.   Have I missed something?  If it
> > > isn't possible
> > > > to specify a resolver for the resolve task, that means I
> > > have to rely on
> > > > defaultResolver in ivy-settings.xml ?   Is there no way to
> > > control this
> > > > from within the Ant script, or must I maintain multiple copies of
> > > > ivy-settings.xml just to choose which resolver to use?
> > >
> > > You can either maintain multiple copies (which maybe only
> > > select the default resolver and include the same common
> > > settings file) or use a property to indicate which resolver
> > > is the default one. I think this is flexible enough so we
> > > don't have to add yet another option on resolve. WDYT?
> >
> > That is the workaround I have converged on (using a property for the
> > default resolver).  It works for me, but it still seems non-intuitive...
> > If you can specify an attribute differently each time you call resolve,
> > then it isn't exactly 'default' anymore.   Long term, I really think the
> > resolve task should have the resolver attribute just as the publish task
> > does.
>
>
> I think switching settings is a good option, not a workaround. What's the
> use case behind selecting the resolver used? Is it to use Ivy in different
> environments (like from home/from office)? Is is to to use different
> repositories depending on the status? Something else? These use cases are
> IMO well covered by settings switching: one settings for each environment
> really make sense, and with settings inclusion and properties, you can avoid
> almost any file data duplication.
>
> But user feedback if supporting a resolver attribute on the resolve task is
> the way to go in the long term.
>
> Xavier
>
>
> >
> >
> > -----------------------------------------
> > ====================================================
> > This message contains PRIVILEGED and CONFIDENTIAL
> > information that is intended only for use by the
> > named recipient. If you are not the named recipient,
> > any disclosure, dissemination, or action based on
> > the contents of this message is prohibited. In such
> > case please notify us and destroy and delete all
> > copies of this transmission.  Thank you.
> > ====================================================
> >
>
>
>
> --
> Xavier Hanin - Independent Java Consultant
> http://xhab.blogspot.com/
> http://ant.apache.org/ivy/
> http://www.xoocode.org/

RE: How to specify which resolver to use at resolve time?

Posted by "Brown, Carlton" <Ca...@compucredit.com>.
> -----Original Message-----
> From: Xavier Hanin [mailto:xavier.hanin@gmail.com] 
> Sent: Friday, March 28, 2008 9:24 AM
> To: ivy-user@ant.apache.org
> Subject: Re: How to specify which resolver to use at resolve time?
> 
> On Fri, Mar 28, 2008 at 1:54 PM, Brown, Carlton < 
> Carlton.Brown@compucredit.com> wrote:
> 
> > > -----Original Message-----
> > > From: Xavier Hanin [mailto:xavier.hanin@gmail.com]
> > > Sent: Friday, March 28, 2008 4:16 AM
> > > To: ivy-user@ant.apache.org
> > > Subject: Re: How to specify which resolver to use at resolve time?
> > >
> > > On Thu, Mar 27, 2008 at 8:34 PM, Brown, Carlton < 
> > > Carlton.Brown@compucredit.com> wrote:
> > >
> > > > The publish and install tasks allow me to specify which
> > > resolver to use
> > > > for publishing (or installing).   I don't see this
> > > capability for the
> > > > resolve task, however.   Have I missed something?  If it
> > > isn't possible
> > > > to specify a resolver for the resolve task, that means I
> > > have to rely on
> > > > defaultResolver in ivy-settings.xml ?   Is there no way to
> > > control this
> > > > from within the Ant script, or must I maintain multiple 
> copies of 
> > > > ivy-settings.xml just to choose which resolver to use?
> > >
> > > You can either maintain multiple copies (which maybe only 
> select the 
> > > default resolver and include the same common settings 
> file) or use a 
> > > property to indicate which resolver is the default one. I 
> think this 
> > > is flexible enough so we don't have to add yet another option on 
> > > resolve. WDYT?
> >
> > That is the workaround I have converged on (using a 
> property for the 
> > default resolver).  It works for me, but it still seems 
> non-intuitive...
> > If you can specify an attribute differently each time you 
> call resolve,
> > then it isn't exactly 'default' anymore.   Long term, I 
> really think the
> > resolve task should have the resolver attribute just as the publish 
> > task does.
> 
> 
> I think switching settings is a good option, not a 
> workaround. What's the use case behind selecting the resolver 
> used? Is it to use Ivy in different environments (like from 
> home/from office)? Is is to to use different repositories 
> depending on the status? Something else? These use cases are 
> IMO well covered by settings switching: one settings for each 
> environment really make sense, and with settings inclusion 
> and properties, you can avoid almost any file data duplication.

It's really a design preference to me... The use cases are all covered,
but they all add unnecessary complexity for the user (maintaining
multiple ivy-settings.xml files with pointers back to the 'main' one).
It's very convenient that the publish task does not require this
complexity.  From a user standpoint, it's the simplest thing that works.
From a design and documentation standpoint, I would think it is
desirable for similar tasks to work in similar ways.  But as you said,
the use cases are covered (even if they are complexity-adding
workarounds, IMO).

-----------------------------------------
====================================================
This message contains PRIVILEGED and CONFIDENTIAL
information that is intended only for use by the 
named recipient. If you are not the named recipient,
any disclosure, dissemination, or action based on 
the contents of this message is prohibited. In such
case please notify us and destroy and delete all 
copies of this transmission.  Thank you.
====================================================

Re: How to specify which resolver to use at resolve time?

Posted by Xavier Hanin <xa...@gmail.com>.
On Fri, Mar 28, 2008 at 1:54 PM, Brown, Carlton <
Carlton.Brown@compucredit.com> wrote:

> > -----Original Message-----
> > From: Xavier Hanin [mailto:xavier.hanin@gmail.com]
> > Sent: Friday, March 28, 2008 4:16 AM
> > To: ivy-user@ant.apache.org
> > Subject: Re: How to specify which resolver to use at resolve time?
> >
> > On Thu, Mar 27, 2008 at 8:34 PM, Brown, Carlton <
> > Carlton.Brown@compucredit.com> wrote:
> >
> > > The publish and install tasks allow me to specify which
> > resolver to use
> > > for publishing (or installing).   I don't see this
> > capability for the
> > > resolve task, however.   Have I missed something?  If it
> > isn't possible
> > > to specify a resolver for the resolve task, that means I
> > have to rely on
> > > defaultResolver in ivy-settings.xml ?   Is there no way to
> > control this
> > > from within the Ant script, or must I maintain multiple copies of
> > > ivy-settings.xml just to choose which resolver to use?
> >
> > You can either maintain multiple copies (which maybe only
> > select the default resolver and include the same common
> > settings file) or use a property to indicate which resolver
> > is the default one. I think this is flexible enough so we
> > don't have to add yet another option on resolve. WDYT?
>
> That is the workaround I have converged on (using a property for the
> default resolver).  It works for me, but it still seems non-intuitive...
> If you can specify an attribute differently each time you call resolve,
> then it isn't exactly 'default' anymore.   Long term, I really think the
> resolve task should have the resolver attribute just as the publish task
> does.


I think switching settings is a good option, not a workaround. What's the
use case behind selecting the resolver used? Is it to use Ivy in different
environments (like from home/from office)? Is is to to use different
repositories depending on the status? Something else? These use cases are
IMO well covered by settings switching: one settings for each environment
really make sense, and with settings inclusion and properties, you can avoid
almost any file data duplication.

But user feedback if supporting a resolver attribute on the resolve task is
the way to go in the long term.

Xavier


>
>
> -----------------------------------------
> ====================================================
> This message contains PRIVILEGED and CONFIDENTIAL
> information that is intended only for use by the
> named recipient. If you are not the named recipient,
> any disclosure, dissemination, or action based on
> the contents of this message is prohibited. In such
> case please notify us and destroy and delete all
> copies of this transmission.  Thank you.
> ====================================================
>



-- 
Xavier Hanin - Independent Java Consultant
http://xhab.blogspot.com/
http://ant.apache.org/ivy/
http://www.xoocode.org/

RE: How to specify which resolver to use at resolve time?

Posted by "Brown, Carlton" <Ca...@compucredit.com>.
> -----Original Message-----
> From: Xavier Hanin [mailto:xavier.hanin@gmail.com] 
> Sent: Friday, March 28, 2008 4:16 AM
> To: ivy-user@ant.apache.org
> Subject: Re: How to specify which resolver to use at resolve time?
> 
> On Thu, Mar 27, 2008 at 8:34 PM, Brown, Carlton < 
> Carlton.Brown@compucredit.com> wrote:
> 
> > The publish and install tasks allow me to specify which 
> resolver to use
> > for publishing (or installing).   I don't see this 
> capability for the
> > resolve task, however.   Have I missed something?  If it 
> isn't possible
> > to specify a resolver for the resolve task, that means I 
> have to rely on
> > defaultResolver in ivy-settings.xml ?   Is there no way to 
> control this
> > from within the Ant script, or must I maintain multiple copies of 
> > ivy-settings.xml just to choose which resolver to use?
> 
> You can either maintain multiple copies (which maybe only 
> select the default resolver and include the same common 
> settings file) or use a property to indicate which resolver 
> is the default one. I think this is flexible enough so we 
> don't have to add yet another option on resolve. WDYT?

That is the workaround I have converged on (using a property for the
default resolver).  It works for me, but it still seems non-intuitive...
If you can specify an attribute differently each time you call resolve,
then it isn't exactly 'default' anymore.   Long term, I really think the
resolve task should have the resolver attribute just as the publish task
does.

-----------------------------------------
====================================================
This message contains PRIVILEGED and CONFIDENTIAL
information that is intended only for use by the 
named recipient. If you are not the named recipient,
any disclosure, dissemination, or action based on 
the contents of this message is prohibited. In such
case please notify us and destroy and delete all 
copies of this transmission.  Thank you.
====================================================

Re: How to specify which resolver to use at resolve time?

Posted by Xavier Hanin <xa...@gmail.com>.
On Thu, Mar 27, 2008 at 8:34 PM, Brown, Carlton <
Carlton.Brown@compucredit.com> wrote:

> The publish and install tasks allow me to specify which resolver to use
> for publishing (or installing).   I don't see this capability for the
> resolve task, however.   Have I missed something?  If it isn't possible
> to specify a resolver for the resolve task, that means I have to rely on
> defaultResolver in ivy-settings.xml ?   Is there no way to control this
> from within the Ant script, or must I maintain multiple copies of
> ivy-settings.xml just to choose which resolver to use?

You can either maintain multiple copies (which maybe only select the default
resolver and include the same common settings file) or use a property to
indicate which resolver is the default one. I think this is flexible enough
so we don't have to add yet another option on resolve. WDYT?

Xavier

>
>
>
>
> -----------------------------------------
> ====================================================
> This message contains PRIVILEGED and CONFIDENTIAL
> information that is intended only for use by the
> named recipient. If you are not the named recipient,
> any disclosure, dissemination, or action based on
> the contents of this message is prohibited. In such
> case please notify us and destroy and delete all
> copies of this transmission.  Thank you.
> ====================================================




-- 
Xavier Hanin - Independent Java Consultant
http://xhab.blogspot.com/
http://ant.apache.org/ivy/
http://www.xoocode.org/