You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by asdas adasads <ze...@gmail.com> on 2010/12/03 01:14:20 UTC

Dependency overriding.

Hi,

    My project has two pom's. One is a called a super pom and contains basic
configuration for the whole project. Second pom declares "super pom" as its
parent.
In super pom you can find these dependency:

       <dependency>
                <groupId>org.slf4j</groupId>
               <artifactId>slf4j-log4j12</artifactId>
                <version>1.5.6</version>
       </dependency>

Which defines what kind of implementation all project should use for
logging. In the second pom (child) I want to declare different logging
implementation, namely:

       <dependency>
           <groupId>org.slf4j</groupId>
           <artifactId>slf4j-nop</artifactId>
           <version>1.5.6</version>
       </dependency>

But it seems that the maven builds classpath is a way where dependency from
parent is before, dependency from child. So nop logging will not be used
during execution.
Is there any way change that ? (to use nop as logging implementation) I
cannot change "super pom" file. The behavior what I'm interested is the same
as method overriding in OOP.

- John

Re: Dependency overriding.

Posted by per-henrik hedman <ph...@gmail.com>.
Hi John,
there is such a thing as dependency exclusions, that might help you in this:
http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

cheers,
Phh

On Fri, Dec 3, 2010 at 1:14 AM, asdas adasads
<ze...@gmail.com> wrote:
> Hi,
>
>    My project has two pom's. One is a called a super pom and contains basic
> configuration for the whole project. Second pom declares "super pom" as its
> parent.
> In super pom you can find these dependency:
>
>       <dependency>
>                <groupId>org.slf4j</groupId>
>               <artifactId>slf4j-log4j12</artifactId>
>                <version>1.5.6</version>
>       </dependency>
>
> Which defines what kind of implementation all project should use for
> logging. In the second pom (child) I want to declare different logging
> implementation, namely:
>
>       <dependency>
>           <groupId>org.slf4j</groupId>
>           <artifactId>slf4j-nop</artifactId>
>           <version>1.5.6</version>
>       </dependency>
>
> But it seems that the maven builds classpath is a way where dependency from
> parent is before, dependency from child. So nop logging will not be used
> during execution.
> Is there any way change that ? (to use nop as logging implementation) I
> cannot change "super pom" file. The behavior what I'm interested is the same
> as method overriding in OOP.
>
> - John
>

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


Re: Dependency overriding.

Posted by Anders Hammar <an...@hammar.net>.
FIrst, don't use the name "super pom". In the Maven world, there is one pom
called the super pom and it is the pom all other poms inherits implicitly.
It's part of Maven core. DOn't use that name for anything else as it will
cause confusion. What you have is a parent pom.

Regarding your question. You should be able to override the version through
a dependencyManagement section in your pom. Per's suggestion regarding
exclusion will not work in this case.

Also, I think that you should use dependencyManagement in your parent pom as
well, not an actual dependency. Please read about the difference here:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

/Anders

On Fri, Dec 3, 2010 at 01:14, asdas adasads <ze...@gmail.com>wrote:

> Hi,
>
>    My project has two pom's. One is a called a super pom and contains basic
> configuration for the whole project. Second pom declares "super pom" as its
> parent.
> In super pom you can find these dependency:
>
>       <dependency>
>                <groupId>org.slf4j</groupId>
>               <artifactId>slf4j-log4j12</artifactId>
>                <version>1.5.6</version>
>       </dependency>
>
> Which defines what kind of implementation all project should use for
> logging. In the second pom (child) I want to declare different logging
> implementation, namely:
>
>       <dependency>
>           <groupId>org.slf4j</groupId>
>           <artifactId>slf4j-nop</artifactId>
>           <version>1.5.6</version>
>       </dependency>
>
> But it seems that the maven builds classpath is a way where dependency from
> parent is before, dependency from child. So nop logging will not be used
> during execution.
> Is there any way change that ? (to use nop as logging implementation) I
> cannot change "super pom" file. The behavior what I'm interested is the
> same
> as method overriding in OOP.
>
> - John
>

Re: Dependency overriding.

Posted by Ron Wheeler <rw...@artifact-software.com>.
On 03/12/2010 11:12 AM, Laird Nelson wrote:
> On Fri, Dec 3, 2010 at 9:36 AM, Yanko, Curtis<cu...@uhc.com>  wrote:
>
>> We only declare dependencies as<dependencyManagement>  items in our
>> Parent POMs and then declare *versionless* dependencies in each app so
>> they are explicit and comprehensible without having to go look somewhere
>> else (except for versioning which is all in one place too)
>>
> I have often wished for the ability to simply and easily refer to a group of
> dependencyManagement entries with one element.  Going hand-in-hand with this
> would of course be the ability to group and name such groups within the
> dependencyManagement section.

Make a small set of aggregation POMs that build the library JARs that 
most applications use.
This centralizes the choice of version and makes it easy to specify the 
dependencies in application modules since you may only have to specify 5 
or 6 dependencies to pick up 50-60 3rd party and internal libraries.
In those projects, you set the scope of the aggregated JARs to 
"provided" and then provide those libraries at run-time. This makes your 
war files much smaller and your builds much quicker.

Ron
>   So, making this up:
>
>   <dependencyManagement>
>    <dependencyGroup>
>      <id>persistence-dependencies</id>
>      <dependency>
>        <groupId>org.apache.openjpa</groupId>
>        <artifactId>openjpa</artifactId>
>        <version>${openJpaVersion}</version>
>        <scope>test</scope>
>      </dependency>
>      <dependency>
>        <groupId>org.eclipse.persistence</groupId>
>        <artifactId>javax.persistence</artifactId>
>        <version>${eclipseLinkVersion}</version>
>        <scope>test</scope>
>      </dependency>
>      <dependency>
>        <groupId>org.eclipse.persistence</groupId>
>        <artifactId>org.eclipse.persistence.jpa</artifactId>
>        <version>${eclipseLinkVersion}</version>
>        <scope>test</scope>
>      </dependency>
>      <dependency>
>        <groupId>org.eclipse.persistence</groupId>
>        <artifactId>org.eclipse.persistence.core</artifactId>
>        <version>${eclipseLinkVersion}</version>
>        <scope>test</scope>
>      </dependency>
>      <dependency>
>        <groupId>org.hibernate</groupId>
>        <artifactId>hibernate-core</artifactId>
>        <version>${hibernateVersion}</version>
>        <scope>test</scope>
>      </dependency>
>      <dependency>
>        <groupId>org.hibernate</groupId>
>        <artifactId>hibernate-entitymanager</artifactId>
>        <version>${hibernateVersion}</version>
>        <scope>test</scope>
>      </dependency>
>    </dependencyGroup>
> </dependencyManagement>
>
> Then, in a sub-pom:
>
> <dependencies>
>    <dependencyGroup>
>      <id>persistence-dependencies</id>
>    </dependencyGroup>
> </dependencies>
>
> Otherwise, lots of copying and pasting happens!
>
> Best,
> Laird
>


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


Re: Dependency overriding.

Posted by Jörg Schaible <jo...@gmx.de>.
Hi Laird,

Laird Nelson wrote:

> On Fri, Dec 3, 2010 at 9:36 AM, Yanko, Curtis <cu...@uhc.com> wrote:
> 
>> We only declare dependencies as <dependencyManagement> items in our
>> Parent POMs and then declare *versionless* dependencies in each app so
>> they are explicit and comprehensible without having to go look somewhere
>> else (except for versioning which is all in one place too)
>>
> 
> I have often wished for the ability to simply and easily refer to a group
> of
> dependencyManagement entries with one element.  Going hand-in-hand with
> this would of course be the ability to group and name such groups within
> the
> dependencyManagement section.  So, making this up:
> 
>  <dependencyManagement>
>   <dependencyGroup>
>     <id>persistence-dependencies</id>
>     <dependency>
>       <groupId>org.apache.openjpa</groupId>
>       <artifactId>openjpa</artifactId>
>       <version>${openJpaVersion}</version>
>       <scope>test</scope>
>     </dependency>
>     <dependency>
>       <groupId>org.eclipse.persistence</groupId>
>       <artifactId>javax.persistence</artifactId>
>       <version>${eclipseLinkVersion}</version>
>       <scope>test</scope>
>     </dependency>
>     <dependency>
>       <groupId>org.eclipse.persistence</groupId>
>       <artifactId>org.eclipse.persistence.jpa</artifactId>
>       <version>${eclipseLinkVersion}</version>
>       <scope>test</scope>
>     </dependency>
>     <dependency>
>       <groupId>org.eclipse.persistence</groupId>
>       <artifactId>org.eclipse.persistence.core</artifactId>
>       <version>${eclipseLinkVersion}</version>
>       <scope>test</scope>
>     </dependency>
>     <dependency>
>       <groupId>org.hibernate</groupId>
>       <artifactId>hibernate-core</artifactId>
>       <version>${hibernateVersion}</version>
>       <scope>test</scope>
>     </dependency>
>     <dependency>
>       <groupId>org.hibernate</groupId>
>       <artifactId>hibernate-entitymanager</artifactId>
>       <version>${hibernateVersion}</version>
>       <scope>test</scope>
>     </dependency>
>   </dependencyGroup>
> </dependencyManagement>

Declare these artifacts as deps in a project with pom packaging ...

> 
> Then, in a sub-pom:
> 
> <dependencies>
>   <dependencyGroup>
>     <id>persistence-dependencies</id>
>   </dependencyGroup>
> </dependencies>

Reference the pom artifact as compile or runtime (don't forget to set the 
type to pom).

> Otherwise, lots of copying and pasting happens!

- Jörg


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


Re: Dependency overriding.

Posted by Laird Nelson <lj...@gmail.com>.
On Fri, Dec 3, 2010 at 9:36 AM, Yanko, Curtis <cu...@uhc.com> wrote:

> We only declare dependencies as <dependencyManagement> items in our
> Parent POMs and then declare *versionless* dependencies in each app so
> they are explicit and comprehensible without having to go look somewhere
> else (except for versioning which is all in one place too)
>

I have often wished for the ability to simply and easily refer to a group of
dependencyManagement entries with one element.  Going hand-in-hand with this
would of course be the ability to group and name such groups within the
dependencyManagement section.  So, making this up:

 <dependencyManagement>
  <dependencyGroup>
    <id>persistence-dependencies</id>
    <dependency>
      <groupId>org.apache.openjpa</groupId>
      <artifactId>openjpa</artifactId>
      <version>${openJpaVersion}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.persistence</groupId>
      <artifactId>javax.persistence</artifactId>
      <version>${eclipseLinkVersion}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.persistence</groupId>
      <artifactId>org.eclipse.persistence.jpa</artifactId>
      <version>${eclipseLinkVersion}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.eclipse.persistence</groupId>
      <artifactId>org.eclipse.persistence.core</artifactId>
      <version>${eclipseLinkVersion}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>${hibernateVersion}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>${hibernateVersion}</version>
      <scope>test</scope>
    </dependency>
  </dependencyGroup>
</dependencyManagement>

Then, in a sub-pom:

<dependencies>
  <dependencyGroup>
    <id>persistence-dependencies</id>
  </dependencyGroup>
</dependencies>

Otherwise, lots of copying and pasting happens!

Best,
Laird

RE: Dependency overriding.

Posted by "Yanko, Curtis" <cu...@uhc.com>.
How is this an override? You have declared two different things
(different artifactId). But... This is why we don't declare dependencies
in Parent POMs ( I see someone else beat me to the Super POM
clarification).

We only declare dependencies as <dependencyManagement> items in our
Parent POMs and then declare *versionless* dependencies in each app so
they are explicit and comprehensible without having to go look somewhere
else (except for versioning which is all in one place too)

________________________________

Curt Yanko | Continuous Integration Services | UnitedHealth Group IT 
Making IT Happen, one build at a time, 600 times a day
 

> -----Original Message-----
> From: asdas adasads [mailto:zestriddle123456@gmail.com] 
> Sent: Thursday, December 02, 2010 7:14 PM
> To: Maven Users List
> Subject: Dependency overriding.
> 
> Hi,
> 
>     My project has two pom's. One is a called a super pom and 
> contains basic configuration for the whole project. Second 
> pom declares "super pom" as its parent.
> In super pom you can find these dependency:
> 
>        <dependency>
>                 <groupId>org.slf4j</groupId>
>                <artifactId>slf4j-log4j12</artifactId>
>                 <version>1.5.6</version>
>        </dependency>
> 
> Which defines what kind of implementation all project should 
> use for logging. In the second pom (child) I want to declare 
> different logging implementation, namely:
> 
>        <dependency>
>            <groupId>org.slf4j</groupId>
>            <artifactId>slf4j-nop</artifactId>
>            <version>1.5.6</version>
>        </dependency>
> 
> But it seems that the maven builds classpath is a way where 
> dependency from parent is before, dependency from child. So 
> nop logging will not be used during execution.
> Is there any way change that ? (to use nop as logging 
> implementation) I cannot change "super pom" file. The 
> behavior what I'm interested is the same as method overriding in OOP.
> 
> - John
> 

This e-mail, including attachments, may include confidential and/or
proprietary information, and may be used only by the person or entity
to which it is addressed. If the reader of this e-mail is not the intended
recipient or his or her authorized agent, the reader is hereby notified
that any dissemination, distribution or copying of this e-mail is
prohibited. If you have received this e-mail in error, please notify the
sender by replying to this message and delete this e-mail immediately.


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