Maven: reuse the POM file in each project

My goal is actually quite simple, but since there are several (and seemingly complicated ways to do this), I wonder what I need to do ... Therefore, I have certain runtime libraries (in particular, ADF libraries), which are needed is added to each project. This parent pom file will only have JAR dependencies. How can I use this pom file from a child pom file?

+3
source share
2 answers

I don't think using inheritance is a good solution here. Even if each project uses ADF artifacts, you do not want all the pumps to receive these dependencies, so declaring them in the corporate parent pump is not an option.

So, instead, my recommendation would be to create a packaging project pomto group ADF dependencies:

<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 / unmount this project and declare it as a dependency in any project that needs ADF artifacts:

<project>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>com.mycompany</groupId>
      <artifactId>adf-deps</artifactId>
      <version>1.0</version>
      <type>pom</type>
    </dependency>
  </dependencies>
</project>
+8
source

If the child POM file is actually a child (i.e., declares its parent), it inherits the dependencies, and you have nothing to do.

+1
source

Source: https://habr.com/ru/post/1744770/


All Articles