Z
Z
zeratustra2018-08-17 10:58:09
Java
zeratustra, 2018-08-17 10:58:09

How to do a pom.xml setup with multiple "parents"?

Hello!
Tell me a beautiful solution for such a problem.
There is a common

pom.xml for a multi-module project like this:
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>ru.zeratustra</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
      <module>srv</module>
      <module>sdk</module>
    </modules>
  </project>


For all modules with api/sdk
sdk pom.xml looks something like this:
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>ru.zeratustra</groupId>
    <artifactId>sdk</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>ru.zeratustra.sdk</name>
    <description>Service SDK module</description>
    <properties>....</properties>
    <dependencies>....</dependencies>
    <build>
      <plugins>....</plugins>
    </build>
  </project>


For all service modules
srv pom.xml looks something like this
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>ru.zeratustra</groupId>
    <artifactId>srv</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>ru.zeratustra.srv</name>
    <description>Service  module</description>
    <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.0.4.RELEASE</version>
      <relativePath/>
    </parent>
    <properties>....</properties>
    <dependencies>....</dependencies>
    <build>
      <plugins>....</plugins>
    </build>
  </project>


Moreover, at least 70% of the content of the properties, dependencies, plugins blocks is common for all modules. Naturally, I want to put it in the general pom.xml, however, I can’t do it using the parent statement, since the services already have a dependency on spring-boot-starter-parent.
You can implement two parents, one for all srv (which in turn inherits spring-boot-starter-parent) and one for sdk, but I really want to keep one common pom, not two. I also do not want to make a common parent inheriting spring-boot-starter-parent, since this is redundant for sdk modules.
How to be? Is it possible to inherit from multiple parents? How can this be implemented?
Thank you!
upd: the hierarchy I'm trying to build is in the repository

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DS1977, 2018-08-17
@DS1977

You can try with bom
Not the easiest solution, but I can't think of another:

bom-pom
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>ru.zeratustra</groupId>
    <artifactId>bom</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
 <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>ru.zeratustra</groupId>
                <artifactId>parent1</artifactId>
                <scope>import</scope>
                <version>${parent1.version}</version>
                <type>pom</type>
            </dependency>
            <dependency>
                <groupId>ru.zeratustra</groupId>
                <artifactId>parent2</artifactId>
                <scope>import</scope>
                <version>${parent2.version}</version>
                <type>pom</type>
            </dependency>
       </dependencies>
 </dependencyManagement>
  </project>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question