You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Brad O'Hearne <br...@neurofire.com> on 2006/07/03 03:20:20 UTC

Need to include ONLY a new version of a transitive dependency

I have a project which is dependent on a resource we'll call "X". X is 
dependent on a resource called "Y", so in my pom, I am only specifying 
the direct dependency on X. My project builds a WAR, and when packaged, 
X and Y are included. Everything's fine so far. But it turns out, for 
various reasons, I actually need a newer version of Y, than the one that 
X is specifying. If I specify the newer version of Y in my pom.xml file, 
when packaged, both versions of Y are included -- not what I want. So if 
I specify both versions of Y in my pom.xml file, and list the scope of 
the older version as "provided" and the scope of the newer one as 
"compile", neither one is included. How can I get maven to include only 
the newer version of Y when packaging my WAR?

Thanks,

Brad

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Brad O'Hearne <br...@neurofire.com>.
Thanks Wendy, that makes sense. I appreciate you taking the time to 
clarify the matter.

Cheers,

Brad

Wendy Smoak wrote:

> On 7/3/06, Brad O'Hearne <br...@neurofire.com> wrote:
>
>> The detail I've posted prior in this thread shows at least one case
>> where it appears that Maven doesn't do this. The fact that Maven wasn't
>> choosing the proper version, or for that matter, any version (it was
>> including them both), and the groupId's and and artifactId's were
>> identical between my pom.xml and the dependency pom, shows that this
>> doesn't seem to work in all cases. This not working properly is the
>> reason for my original question.
>
>
> All I can do is sympathize -- Maven is working the way it's supposed
> to, but it can only be as good as the data we give it.  Even though
> _you_ think you're working with two versions of the "same" dependency,
> Maven doensn't agree.  One of them moved and is now "different".
>
> The repository metadata is greatly improved over what it was, but
> there are still problems, and unfortunately, you found one.  In this
> case, EHCache 1.2 should *not* have been relocated without also
> relocating the prior versions.
>
> In its defense, Maven *did* try to tell you:
>
> Downloading: 
> http://repo1.maven.org/maven2/ehcache/ehcache/1.2/ehcache-1.2.pom
> 278b downloaded
> [WARNING] While downloading ehcache:ehcache:1.2
>  This artifact has been relocated to net.sf.ehcache:ehcache:1.2.
>
> There's a long thread on Jakarta commons-dev about this very thing, as
> they get ready to move all of their artifacts from the current
> commons-xxx groupIds to org.apache.commons.
>
>> This was only doable this way because ehcache:ehcache had just happened
>> to be moved to net.sf.echcache:ehcache. Had this not been the case, this
>> wouldn't have worked -- I would have had to try to include
>> echcache:ehcache version 1.2 and exclude version 1.1.
>
>
> No.  It was only *necessary* because one of them happened to have moved.
>
> If both of them were in the same groupId, this would have worked
> perfectly from the beginning when you declared a dependency on EHCache
> 1.2.
>
> The <exclusion> is a workaround. The fix is to file a 'Maven
> Evangelism' issue and get the older EHCache versions relocated to the
> same place as v1.2.
>
> HTH,



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Wendy Smoak <ws...@gmail.com>.
On 7/3/06, Brad O'Hearne <br...@neurofire.com> wrote:

> The detail I've posted prior in this thread shows at least one case
> where it appears that Maven doesn't do this. The fact that Maven wasn't
> choosing the proper version, or for that matter, any version (it was
> including them both), and the groupId's and and artifactId's were
> identical between my pom.xml and the dependency pom, shows that this
> doesn't seem to work in all cases. This not working properly is the
> reason for my original question.

All I can do is sympathize -- Maven is working the way it's supposed
to, but it can only be as good as the data we give it.  Even though
_you_ think you're working with two versions of the "same" dependency,
Maven doensn't agree.  One of them moved and is now "different".

The repository metadata is greatly improved over what it was, but
there are still problems, and unfortunately, you found one.  In this
case, EHCache 1.2 should *not* have been relocated without also
relocating the prior versions.

In its defense, Maven *did* try to tell you:

Downloading: http://repo1.maven.org/maven2/ehcache/ehcache/1.2/ehcache-1.2.pom
278b downloaded
[WARNING] While downloading ehcache:ehcache:1.2
  This artifact has been relocated to net.sf.ehcache:ehcache:1.2.

There's a long thread on Jakarta commons-dev about this very thing, as
they get ready to move all of their artifacts from the current
commons-xxx groupIds to org.apache.commons.

> This was only doable this way because ehcache:ehcache had just happened
> to be moved to net.sf.echcache:ehcache. Had this not been the case, this
> wouldn't have worked -- I would have had to try to include
> echcache:ehcache version 1.2 and exclude version 1.1.

No.  It was only *necessary* because one of them happened to have moved.

If both of them were in the same groupId, this would have worked
perfectly from the beginning when you declared a dependency on EHCache
1.2.

The <exclusion> is a workaround. The fix is to file a 'Maven
Evangelism' issue and get the older EHCache versions relocated to the
same place as v1.2.

HTH,
-- 
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Brad O'Hearne <br...@neurofire.com>.
Wendy,

Thanks for the reply. Responses below:

Wendy Smoak wrote:

> On 7/3/06, Brad O'Hearne <br...@neurofire.com> wrote:
>
>> But I still have a question here -- I noticed that in the exclusion,
>> there's no "version" element allowed. I happened to benefit here from
>> the fact that ehcache had actually been moved to net.sf.ehcache, so I
>> used that as the dependency groupId. But I don't quite understand this
>> -- what I am trying to exclude is not ehcache, but a particular version
>> of it. Why isn't a version supported for the exclusion?
>
>
> You don't need a version number on an exclusion because you're always
> trying to get rid of the entire thing.  If you just want a different
> version, you simply declare a dependency on the version you want, and
> Maven will choose the 'nearest' definition.

The detail I've posted prior in this thread shows at least one case 
where it appears that Maven doesn't do this. The fact that Maven wasn't 
choosing the proper version, or for that matter, any version (it was 
including them both), and the groupId's and and artifactId's were 
identical between my pom.xml and the dependency pom, shows that this 
doesn't seem to work in all cases. This not working properly is the 
reason for my original question.

>
> In this case, you *are* trying to completely exclude ehcache:ehcache
> (groupId and artifactId).  As far as Maven is concerned,
> ehcache:ehcache and net.sf.ehcache:ehcache are completely separate
> dependencies.

This was only doable this way because ehcache:ehcache had just happened 
to be moved to net.sf.echcache:ehcache. Had this not been the case, this 
wouldn't have worked -- I would have had to try to include 
echcache:ehcache version 1.2 and exclude version 1.1. In fact, this is 
the original problem, which raised the question of how to explicitly 
exclude one version of a dependency while explicitly including another 
version of a dependency.

I guess the thing that's a bit unnerving is that although we've found a 
workaround, the original problem still exists. Why doesn't Maven 
properly filter out the earlier version of the dependency?

Brad

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Wendy Smoak <ws...@gmail.com>.
On 7/3/06, Brad O'Hearne <br...@neurofire.com> wrote:

> But I still have a question here -- I noticed that in the exclusion,
> there's no "version" element allowed. I happened to benefit here from
> the fact that ehcache had actually been moved to net.sf.ehcache, so I
> used that as the dependency groupId. But I don't quite understand this
> -- what I am trying to exclude is not ehcache, but a particular version
> of it. Why isn't a version supported for the exclusion?

You don't need a version number on an exclusion because you're always
trying to get rid of the entire thing.  If you just want a different
version, you simply declare a dependency on the version you want, and
Maven will choose the 'nearest' definition.

In this case, you *are* trying to completely exclude ehcache:ehcache
(groupId and artifactId).  As far as Maven is concerned,
ehcache:ehcache and net.sf.ehcache:ehcache are completely separate
dependencies.

It might be worth opening a MEV issue to get EHCache 1.1 relocated to
the new groupId.  That would make the exclusion unnecessary as Maven
will see both 1.1 and 1.2 as the same again.

-- 
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Brad O'Hearne <br...@neurofire.com>.
Wendy,

Thanks for the reply. I was able to make it work with the following:

    <dependency>
      <groupId>net.sf.ehcache</groupId>
      <artifactId>ehcache</artifactId>
      <version>1.2</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <groupId>ehcache</groupId>
          <artifactId>ehcache</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

But I still have a question here -- I noticed that in the exclusion, 
there's no "version" element allowed. I happened to benefit here from 
the fact that ehcache had actually been moved to net.sf.ehcache, so I 
used that as the dependency groupId. But I don't quite understand this 
-- what I am trying to exclude is not ehcache, but a particular version 
of it. Why isn't a version supported for the exclusion?

Brad

Wendy Smoak wrote:

> On 7/2/06, Brad O'Hearne <br...@neurofire.com> wrote:
>
>> I have manually gone in and nuked the contents of target, and rebuilt /
>> packaged the WAR. I still get both jars -- I sent another email with the
>> details of this.
>
>
> Examine the output of 'mvn package -X' to see if you can figure out
> where each jar is coming from.
>
> Take a look at mvn help:effective-pom to see if both dependencies are 
> in there.
>
> Look at the poms and artifacts on ibiblio... and:
>  http://www.ibiblio.org/maven2/ehcache/ehcache/1.2/ehcache-1.2.pom
>
> Ehcache 1.2 has been relocated to a different groupId,
> 'net.sf.ehcache' while ehcache 1.1 has not.
>
> Double check that issue that Stephen linked to, but I still think you
> need to <exclude> ehcache:ehcache from your hibernate dependency, then
> declare the newer one.  And use the correct groupId now that we know
> what it is.
>
> If that *still* doesn't work, use mvn archetype:create to set up a
> project, and modify the pom so that it reproduces the problem, then
> let us take a look at that.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Wendy Smoak <ws...@gmail.com>.
On 7/2/06, Brad O'Hearne <br...@neurofire.com> wrote:
> I have manually gone in and nuked the contents of target, and rebuilt /
> packaged the WAR. I still get both jars -- I sent another email with the
> details of this.

Examine the output of 'mvn package -X' to see if you can figure out
where each jar is coming from.

Take a look at mvn help:effective-pom to see if both dependencies are in there.

Look at the poms and artifacts on ibiblio... and:
  http://www.ibiblio.org/maven2/ehcache/ehcache/1.2/ehcache-1.2.pom

Ehcache 1.2 has been relocated to a different groupId,
'net.sf.ehcache' while ehcache 1.1 has not.

Double check that issue that Stephen linked to, but I still think you
need to <exclude> ehcache:ehcache from your hibernate dependency, then
declare the newer one.  And use the correct groupId now that we know
what it is.

If that *still* doesn't work, use mvn archetype:create to set up a
project, and modify the pom so that it reproduces the problem, then
let us take a look at that.

-- 
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Brad O'Hearne <br...@neurofire.com>.
I have manually gone in and nuked the contents of target, and rebuilt / 
packaged the WAR. I still get both jars -- I sent another email with the 
details of this.

Brad

Stephen Duncan wrote:

> Well, 'mvn clean' would not cleanup src/main/webapp/WEB-INF/lib.
> Those files are treated as valid source.
>
> -Stephen
>
> On 7/2/06, Wendy Smoak <ws...@gmail.com> wrote:
>
>> On 7/2/06, Stephen Duncan <st...@gmail.com> wrote:
>> > On 7/2/06, Wendy Smoak <ws...@gmail.com> wrote:
>> > >
>> > > I would:
>> > >  1. declare a dependency on the correct version of Y
>> > >  2. add an exclusion to the X dependency, excluding its transitive
>> > > dependency on Y
>> > >
>> > > --
>> > > Wendy
>> >
>> > This is a bad idea currently due to: 
>> http://jira.codehaus.org/browse/MNG-1797
>>
>> Thanks.  In this case I think the two Y's are really "different".
>> Otherwise there's no way that both of them would be ending up in
>> WEB-INF/lib.
>>
>> (Unless, as you suggested, it's a simple matter of 'mvn clean' not
>> having been run recently...)
>>
>> -- 
>> Wendy
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Stephen Duncan <st...@gmail.com>.
Well, 'mvn clean' would not cleanup src/main/webapp/WEB-INF/lib.
Those files are treated as valid source.

-Stephen

On 7/2/06, Wendy Smoak <ws...@gmail.com> wrote:
> On 7/2/06, Stephen Duncan <st...@gmail.com> wrote:
> > On 7/2/06, Wendy Smoak <ws...@gmail.com> wrote:
> > >
> > > I would:
> > >  1. declare a dependency on the correct version of Y
> > >  2. add an exclusion to the X dependency, excluding its transitive
> > > dependency on Y
> > >
> > > --
> > > Wendy
> >
> > This is a bad idea currently due to: http://jira.codehaus.org/browse/MNG-1797
>
> Thanks.  In this case I think the two Y's are really "different".
> Otherwise there's no way that both of them would be ending up in
> WEB-INF/lib.
>
> (Unless, as you suggested, it's a simple matter of 'mvn clean' not
> having been run recently...)
>
> --
> Wendy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Stephen Duncan Jr
www.stephenduncanjr.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Wendy Smoak <ws...@gmail.com>.
On 7/2/06, Stephen Duncan <st...@gmail.com> wrote:
> On 7/2/06, Wendy Smoak <ws...@gmail.com> wrote:
> >
> > I would:
> >  1. declare a dependency on the correct version of Y
> >  2. add an exclusion to the X dependency, excluding its transitive
> > dependency on Y
> >
> > --
> > Wendy
>
> This is a bad idea currently due to: http://jira.codehaus.org/browse/MNG-1797

Thanks.  In this case I think the two Y's are really "different".
Otherwise there's no way that both of them would be ending up in
WEB-INF/lib.

(Unless, as you suggested, it's a simple matter of 'mvn clean' not
having been run recently...)

-- 
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Stephen Duncan <st...@gmail.com>.
On 7/2/06, Wendy Smoak <ws...@gmail.com> wrote:
>
> I would:
>  1. declare a dependency on the correct version of Y
>  2. add an exclusion to the X dependency, excluding its transitive
> dependency on Y
>
> --
> Wendy

This is a bad idea currently due to: http://jira.codehaus.org/browse/MNG-1797


-- 
Stephen Duncan Jr
www.stephenduncanjr.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Wendy Smoak <ws...@gmail.com>.
On 7/2/06, Brad O'Hearne <br...@neurofire.com> wrote:

> I have a project which is dependent on a resource we'll call "X". X is
> dependent on a resource called "Y", so in my pom, I am only specifying
> the direct dependency on X. My project builds a WAR, and when packaged,
> X and Y are included. Everything's fine so far. But it turns out, for
> various reasons, I actually need a newer version of Y, than the one that
> X is specifying. If I specify the newer version of Y in my pom.xml file,
> when packaged, both versions of Y are included -- not what I want.

It sounds like Maven doesn't think the two versions of Y are really
the same dependency.  Do the groupId and artifactId match exactly?

> So if
> I specify both versions of Y in my pom.xml file, and list the scope of
> the older version as "provided" and the scope of the newer one as
> "compile", neither one is included.

This doesn't really fit with the behavior you described earlier, but
if you look at the output of mvn -X you'll probably find that the
'provided' scope overrides compile.

I would:
 1. declare a dependency on the correct version of Y
 2. add an exclusion to the X dependency, excluding its transitive
dependency on Y

-- 
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Brad O'Hearne <br...@neurofire.com>.
Stephen,

Thanks for the reply. I am listing hibernate-3.1.jar as a dependency in 
my pom.xml as this:

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate</artifactId>
      <version>3.1</version>
      <scope>compile</scope>
    </dependency>

This dependency brings in the transitive dependency of ehcache-1.1.jar. 
I need ehcache-1.2.jar. So I put this in my pom.xml:

    <dependency>
      <groupId>ehcache</groupId>
      <artifactId>ehcache</artifactId>
      <version>1.2</version>
      <scope>compile</scope>
    </dependency>

When I compile and package my WAR, I find that it has included BOTH 
ehcache-1.1.jar and ehcache-1.2.jar. The artifactId and groupId of 
echcache from my pom.xml and from the ibiblio hibernate-3.1.pom are 
identical -- here is the hibernate-3.1.pom:

    <dependency>
      <groupId>ehcache</groupId>
      <artifactId>ehcache</artifactId>
      <version>1.1</version>
    </dependency>

The older version of ehcache (or for that matter, any dependency) is not in my source tree. So in other words, unless I am missing something, if the expected behavior is for
Maven to filter out the older jar, then Maven for some reason is not working properly. 

Any other thoughts are appreciated!

Brad


Stephen Duncan wrote:

> It should not occur that the older version is included if you specify
> a new version directly in your pom.  Can you provide more details?
> Also, make sure the older version is not your source tree (for
> instance, already in src/main/webapp/WEB-INF/lib from running
> war:inplace or something like it)
>
> - Stephen
>
> On 7/2/06, Brad O'Hearne <br...@neurofire.com> wrote:
>
>> I have a project which is dependent on a resource we'll call "X". X is
>> dependent on a resource called "Y", so in my pom, I am only specifying
>> the direct dependency on X. My project builds a WAR, and when packaged,
>> X and Y are included. Everything's fine so far. But it turns out, for
>> various reasons, I actually need a newer version of Y, than the one that
>> X is specifying. If I specify the newer version of Y in my pom.xml file,
>> when packaged, both versions of Y are included -- not what I want. So if
>> I specify both versions of Y in my pom.xml file, and list the scope of
>> the older version as "provided" and the scope of the newer one as
>> "compile", neither one is included. How can I get maven to include only
>> the newer version of Y when packaging my WAR?
>>
>> Thanks,
>>
>> Brad
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Need to include ONLY a new version of a transitive dependency

Posted by Stephen Duncan <st...@gmail.com>.
It should not occur that the older version is included if you specify
a new version directly in your pom.  Can you provide more details?
Also, make sure the older version is not your source tree (for
instance, already in src/main/webapp/WEB-INF/lib from running
war:inplace or something like it)

- Stephen

On 7/2/06, Brad O'Hearne <br...@neurofire.com> wrote:
> I have a project which is dependent on a resource we'll call "X". X is
> dependent on a resource called "Y", so in my pom, I am only specifying
> the direct dependency on X. My project builds a WAR, and when packaged,
> X and Y are included. Everything's fine so far. But it turns out, for
> various reasons, I actually need a newer version of Y, than the one that
> X is specifying. If I specify the newer version of Y in my pom.xml file,
> when packaged, both versions of Y are included -- not what I want. So if
> I specify both versions of Y in my pom.xml file, and list the scope of
> the older version as "provided" and the scope of the newer one as
> "compile", neither one is included. How can I get maven to include only
> the newer version of Y when packaging my WAR?
>
> Thanks,
>
> Brad
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Stephen Duncan Jr
www.stephenduncanjr.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org