Reuse Maven in Pores

In our Maven project, we are trying to create the following directory structure (about 80 projects in total, only some of them are shown so that you get this idea):

myappli      (pom)
-- module1       (pom)
--|-- utils    (pom)
--|-- ejb       (pom)
--|--|-- myappli-module1-a-ejb    (jar)
--|--|-- myappli-module1-b-ejb    (jar)
--|-- war       (pom)
--|-- applet       (pom)
...
-- module6       (pom)
--|-- utils       (pom)
--|-- ejb       (pom)
--|--|-- myappli-module6-c-ejb    (jar)
--|-- war       (pom)
--|-- applet       (pom)

Note. This is a flat structure for Maven, since all non-leaf projects have a packagingpom value . (cf BetterBuildsWithMaven book).

We define the dependency versions in the " dependencyManagement" in " myappli" pom. It works great.

Our problem is reusing the dependencies themselves . For example, ejb dependencies are common to all ejb projects (by design). We do not want to cut-paste and support all this with every change!

" " ejb ejb . :

  • Maven "parent pom" , , .
  • Maven ( dependencyManagement)
  • XML- . pom, ,
    "Reason: Parse error reading POM. Reason: could not resolve entity named 'ejbDependencies'":

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE project [
    <!ENTITY ejbDependencies SYSTEM "./ejbDependencies.txt">
    ]>
    <project ...
    ...
    &ejbDependencies;
    ...


. , , - .

ejb, . (mvn compile), , javax.ejb .

. "mvn install" .

:

<project ...>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.company</groupId>
    <artifactId>myproj-maven</artifactId>
    <version>3.1-SNAPSHOT</version>
  </parent>

  <groupId>com.company</groupId>
  <artifactId>myproj-maven-ejb</artifactId>
  <version>${myproj-version}</version>
  <packaging>pom</packaging>

  <dependencies>
    <dependency>
      <groupId>javax.ejb</groupId>
      <artifactId>ejb</artifactId>
    </dependency>

    <dependency>
      <groupId>ojdbc</groupId>
      <artifactId>ojdbc</artifactId>
    </dependency>
  </dependencies>
</project>

---------------------------------
<project ...>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.company</groupId>
    <artifactId>myproj-identite-ejb</artifactId>
    <version>3.1-SNAPSHOT</version>
  </parent>

  <groupId>com.company</groupId>
  <artifactId>myproj-identite-metier</artifactId>
  <name>SNR IDENTITE METIER</name>
  <version>2.0.1</version>
  <packaging>ejb</packaging>

  <dependencies>
    <dependency>
      <groupId>com.company</groupId>
      <artifactId>myproj-maven-ejb</artifactId>
      <version>${myproj-version}</version>
      <type>pom</type>
    </dependency>
  </dependencies>
</project>

, - , , .
Maven, maven, maven.
.

+---maven
|   \---ejb
+---identite
|   +---ejb
|   |   \---SNR_IDENTITE_METIER

Edited

, , . Maven, : - (

Maven. . , , !

+5
2

? (. Maven ).

-.

+2

pom .

pom :

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example</groupId>
  <artifactId>persistence-deps</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>

  <dependencies>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate</artifactId>
      <version>${hibernateVersion}</version>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-annotations</artifactId>
      <version>${hibernateAnnotationsVersion}</version>
    </dependency>
  </dependencies>
</project>

:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>persistence-deps</artifactId>
  <version>1.0</version>
  <type>pom</type>
</dependency>

. Maven, - .

+9

All Articles