You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Abitfarago Cini <ci...@gmail.com> on 2013/01/15 18:16:22 UTC

Maven dependencies - best practice

Hi,

I am testing the Maven dependecies. In a parent-child project arhitecture I
am using many frameworks
(log4j, xdoclet, etc) and these are installed in may local repository and I
am able to use them.

I created and installed a POM, called "x-deps", to manage the dependecies:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>sk</groupId>
  <artifactId>x-deps</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <dependencyManagement>
      <dependencies>
          <dependency>
              <groupId>log4j</groupId>
              <artifactId>log4j</artifactId>
              <version>1.2.8</version>
          </dependency>
          <dependency>
              <groupId>xdoclet</groupId>
              <artifactId>xdoclet</artifactId>
              <version>2.0.3</version>
          </dependency>
      </dependencies>
  </dependencyManagement>
</project>

In a parent POM, called "a", I set the dependecyManager for "x-deps":

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>sk</groupId>
  <artifactId>a</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <modules>
      <module>../b</module>
  </modules>
  <dependencyManagement>
      <dependencies>
          <dependency>
              <groupId>sk</groupId>
              <artifactId>x-deps</artifactId>
              <version>0.0.1-SNAPSHOT</version>
              <type>pom</type>
          </dependency>
      </dependencies>
  </dependencyManagement>
</project>

In its child POM, called "b", I would like to add the dependency only for
log4j:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <artifactId>b</artifactId>
  <parent>
      <groupId>sk</groupId>
      <artifactId>a</artifactId>
      <version>0.0.1-SNAPSHOT</version>
  </parent>
  <dependencies>
      <dependency>
          <groupId>log4j</groupId>
          <artifactId>log4j</artifactId>
      </dependency>
  </dependencies>
</project>

When I want to validate my POM "a" I get this error:

error: 'dependencies.dependency.version' for log4j:logj:jar is missing

Can somebody help me?

SK

Re: Maven dependencies - best practice

Posted by th...@vkb.de.
Hi,

> I am testing the Maven dependecies. In a parent-child project 
arhitecture I
> am using many frameworks
> (log4j, xdoclet, etc) and these are installed in may local repository 
and I
> am able to use them.
> 
> I created and installed a POM, called "x-deps", to manage the 
dependecies:

*snip*

> 
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd">
>   <modelVersion>4.0.0</modelVersion>
>   <groupId>sk</groupId>
>   <artifactId>x-deps</artifactId>
>   <version>0.0.1-SNAPSHOT</version>
>   <packaging>pom</packaging>
>   <dependencyManagement>
>       <dependencies>
>           <dependency>
>               <groupId>log4j</groupId>
>               <artifactId>log4j</artifactId>
>               <version>1.2.8</version>
>           </dependency>
>           <dependency>
>               <groupId>xdoclet</groupId>
>               <artifactId>xdoclet</artifactId>
>               <version>2.0.3</version>
>           </dependency>
>       </dependencies>
>   </dependencyManagement>
> </project>
> 
> In a parent POM, called "a", I set the dependecyManager for "x-deps":
> 
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd">
>   <modelVersion>4.0.0</modelVersion>
>   <groupId>sk</groupId>
>   <artifactId>a</artifactId>
>   <version>0.0.1-SNAPSHOT</version>
>   <packaging>pom</packaging>
>   <modules>
>       <module>../b</module>
>   </modules>
>   <dependencyManagement>
>       <dependencies>
>           <dependency>
>               <groupId>sk</groupId>
>               <artifactId>x-deps</artifactId>
>               <version>0.0.1-SNAPSHOT</version>
>               <type>pom</type>
>           </dependency>
>       </dependencies>
>   </dependencyManagement>
> </project>
> 
> In its child POM, called "b", I would like to add the dependency only 
for
> log4j:
> 
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd">
>   <modelVersion>4.0.0</modelVersion>
>   <artifactId>b</artifactId>
>   <parent>
>       <groupId>sk</groupId>
>       <artifactId>a</artifactId>
>       <version>0.0.1-SNAPSHOT</version>
>   </parent>
>   <dependencies>
>       <dependency>
>           <groupId>log4j</groupId>
>           <artifactId>log4j</artifactId>
>       </dependency>
>   </dependencies>
> </project>
> 
> When I want to validate my POM "a" I get this error:
> 
> error: 'dependencies.dependency.version' for log4j:logj:jar is missing
> 
> Can somebody help me?

Quite easy:
In the referenced parent sk:a:0.0.1-SNAPSHOT you only manage a dependency 
for sk:x-deps:0.0.1-SNAPSHOT (which isn't used in b, btw), but not for the 
real dependencies you're using in your project b...

To use them, move the dependency management section from x-deps to your 
project a. That should do the trick.


HTH

Thorsten

Re: Maven dependencies - best practice

Posted by Thomas Broyer <t....@gmail.com>.
You need to use the 'import' scope:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies

On Tue, Jan 15, 2013 at 6:16 PM, Abitfarago Cini
<ci...@gmail.com> wrote:
> Hi,
>
> I am testing the Maven dependecies. In a parent-child project arhitecture I
> am using many frameworks
> (log4j, xdoclet, etc) and these are installed in may local repository and I
> am able to use them.
>
> I created and installed a POM, called "x-deps", to manage the dependecies:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd">
>   <modelVersion>4.0.0</modelVersion>
>   <groupId>sk</groupId>
>   <artifactId>x-deps</artifactId>
>   <version>0.0.1-SNAPSHOT</version>
>   <packaging>pom</packaging>
>   <dependencyManagement>
>       <dependencies>
>           <dependency>
>               <groupId>log4j</groupId>
>               <artifactId>log4j</artifactId>
>               <version>1.2.8</version>
>           </dependency>
>           <dependency>
>               <groupId>xdoclet</groupId>
>               <artifactId>xdoclet</artifactId>
>               <version>2.0.3</version>
>           </dependency>
>       </dependencies>
>   </dependencyManagement>
> </project>
>
> In a parent POM, called "a", I set the dependecyManager for "x-deps":
>
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd">
>   <modelVersion>4.0.0</modelVersion>
>   <groupId>sk</groupId>
>   <artifactId>a</artifactId>
>   <version>0.0.1-SNAPSHOT</version>
>   <packaging>pom</packaging>
>   <modules>
>       <module>../b</module>
>   </modules>
>   <dependencyManagement>
>       <dependencies>
>           <dependency>
>               <groupId>sk</groupId>
>               <artifactId>x-deps</artifactId>
>               <version>0.0.1-SNAPSHOT</version>
>               <type>pom</type>
>           </dependency>
>       </dependencies>
>   </dependencyManagement>
> </project>
>
> In its child POM, called "b", I would like to add the dependency only for
> log4j:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd">
>   <modelVersion>4.0.0</modelVersion>
>   <artifactId>b</artifactId>
>   <parent>
>       <groupId>sk</groupId>
>       <artifactId>a</artifactId>
>       <version>0.0.1-SNAPSHOT</version>
>   </parent>
>   <dependencies>
>       <dependency>
>           <groupId>log4j</groupId>
>           <artifactId>log4j</artifactId>
>       </dependency>
>   </dependencies>
> </project>
>
> When I want to validate my POM "a" I get this error:
>
> error: 'dependencies.dependency.version' for log4j:logj:jar is missing
>
> Can somebody help me?
>
> SK



-- 
Thomas Broyer
/tɔ.ma.bʁwa.je/

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