You are looking for the impossible.

You want A to work with any version of libjar

You want B to use A but not know which version of libjar the A it is using
depends on... actually to be independent of the version of libjar that A
depends on... but also to bundle the specific one...

Rethink what you are asking and you will see that you are asking an
impossible request... you are asking somebody to hop on one leg and
mandating that the one leg be both their left and right leg.

When you are asking an impossibility, that is usually a sign that you are
going at things the wrong way.

If A is going to become part of a fatjar at some point, you need to make a
decision *at the point of creating the fatjar* as to which libjar will be
included within A.

Or else perhaps, you include all versions of libjar and provide a means for
A to decide which version it wants... there are many ways to achieve this...

* use the service provider pattern to introduce another shim layer and then
use the shade plugin to put all the shim impl libjar deps into independent
package namespaces
* use a custom classloader and package libjar as resources, so that A's
entry point loads the correct libjar at runtime
* etc.

With the above you would be including *all* versions of libjar within A and
the whole thing becomes moot anyway...

-Stephen


On 11 December 2013 00:52, Liu, Raymond <raymond....@intel.com> wrote:

> Thanks Stephen
>
>         I see your solution is let B manage the libjar version. While this
> is against my wish, I wish B to know nothing about A's internal
> implementation. In the future, A might depends on a v3.0 libjar, I do wish
> to just repackage B to make it work not revise B's code or assembly rules.
> And sometime A might be buried deep in the dependent tree, Those project
> might not even aware it depends on A, they just wish it works on whatever
> current A's binary jar, which then need the right libjar dependency when
> assembly.
>
>         And I know it seems hard to use profiles to manipulate
> dependencies. While by theory, I think this is a reasonable requirement
> that a project do not need to take care of its dependencies' internal
> implementation of what it depends on, It just wish it works. E.g. if the
> POM file is installed in a way that when it build with profile, the
> corresponding dependencies and any other modifying is fill in the final POM
> file. ( since the profile is not used anyway when resolve dependencies, why
> keep it there? For source jar? ) Then those project depend on it won't
> worry about A's profile, it's already the correct one which been used on
> building A with this installed or downloaded binary jar.
>
>         So , using profile might not be the right solution, While if there
> isn't an automatic way to meet this requirement, can I take it as a feature
> missing?
>
> Best Regards,
> Raymond Liu
>
> -----Original Message-----
> From: Stephen Connolly [mailto:stephen.alan.conno...@gmail.com]
> Sent: Tuesday, December 10, 2013 6:57 PM
> To: Maven Users List
> Subject: Re: How to resolve right dependency which enabled and
> built/install with profile?
>
> Using profiles to manipulate dependencies is a route to madness.
>
> An modules dependencies should be a constant... It was a mistake to allow
> <dependencies> within <profile>.
>
> The correct solution is to create additional modules that aggregate in the
> corresponding lib versions (this is also a bad plan, but less worse than
> your current plan by quite some margin). The additional modules would
> depend on A and the respective version of libjar and bundle the two
> together.
>
> Then B can depend if the corresponding internmediate... Now at this point
> you will start to see the madness returning... That is if you need two
> versions of B.
>
> The better solution is to just let B depend in A and then do the fatjar as
> the final later after B and *override* the transitive dep on libjar in the
> two fatjar building modules
>
> On Tuesday, 10 December 2013, Liu, Raymond wrote:
>
> > Hi
> >
> > I have a project with module A that will be built with or without
> > profile say -Pnewlib , thus I can have it build with different version
> > of library dependency let's say by default use libjar-1.0 and when
> > -Pnewlib will use libjar-2.0.
> >
> > Then, I have a module B to depends on module A. The issue is that how
> > can I get the right dependency in module B for libjar? I want to
> > assemble a fat jar so I need to figure out which version of libjar to
> include.
> >
> > In my test, it seems to me that when mvn -Pnewlib install module A,
> > though it will build with libjar-2.0. but the installed pom do not
> reflect this.
> > Thus when module B resolve the dependency, it will resolve the
> > dependency as libjar-1.0 ( though when building module B, -Pnewlib is
> > also passed in, But I think this will not pass to the dependent
> > package when resolve the dependency).
> >
> > I don't want to have module B know anything about the libjar-1.0 and
> > libjar-2.0. it should handle by module A, and module B just simply
> > call into module A.
> >
> > Actually, I think this apply the same if A and B are not modules in
> > one project, but standalone projects. In which case B will not define
> > profile at all.
> >
> > So how can I achieve this goal? say, A take care of lib dependency
> > when build and install. B who depends on A, when assembly can retrive
> > the right lib dependency.
> >
> > Best Regards,
> > Raymond Liu
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
> > <javascript:;> For additional commands, e-mail:
> > users-h...@maven.apache.org<javascript:;>
> >
> >
>
> --
> Sent from my phone
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
> For additional commands, e-mail: users-h...@maven.apache.org
>
>

Reply via email to