views:

109

answers:

2

My goal is pretty simple actually but since there are multiple (and seemingly complex ways to do this) I wonder what I need to do... So I have certain runtime libraries (ADF libraries in particular) that are needed to be added to every project. This parent pom file will just have JAR dependencies in it. How can I use this pom file from a child pom file?

+1  A: 

If the child POM file is actually a child (i.e. declares its parent), then it will inherit the dependencies and there is nothing left for you to do.

Thomas Lötzer
+5  A: 

I don't think that using inheritance is a good solution here. Even if every project uses ADF artifacts, you don't want all poms to get these dependencies so declaring them in a corporate parent pom is not really an option.

So, instead, my recommendation would be to create a project with pom packaging to group the ADF dependencies together:

<project>
  <groupId>com.mycompany</groupId>
  <artifactId>adf-deps</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>
  <dependencies>
    <dependency>
      <groupId>some.groupId</groupId>
      <artifactId>adf-artifact-1</artifactId>
      <version>${jdev.version}</version>
    </dependency>
    ...
    <dependency>
      <groupId>some.groupId</groupId>
      <artifactId>adf-artifact-n</artifactId>
      <version>${jdev.version}</version>
    </dependency>
  </dependencies>
  <properties>
    <jdev.version>10.1.3</jdev.version>
  </properties>
</project>

Then, install/deploy this project and declare it as dependency in any project that needs the ADF artifacts:

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>com.mycompany</groupId>
      <artifactId>adf-deps</artifactId>
      <version>1.0</version>
      <type>pom</type>
    </dependency>
  </dependencies>
</project>
Pascal Thivent
+1 for recommending composition over inheritance. This actually helps in two ways, it allows for easy reuse of dependency sets and allows easier upgrade to new versions of those dependency sets.
sal