0

I am playing with maven multi module spring boot (v2.1) projects and thought I would be super clever and nest modules within other modules. The purpose of this project is to run different reports, and in the data section I wanted to split the reports by type for manageability, also to share some functionality wike writers, and base classes, as they will be used in every report

below is a screen cap of the hierarchy, but basically, i have a parent pom using (skipping the dependency and build sections): enter image description here

    <packaging>pom</packaging>
<modules>
    <module>adhoc-web</module>
    <module>adhoc-data</module>
</modules>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

the children of the parent pom are a web project and a data project. the data pom looks like (skipping the dependency and build sections):

    <parent>
    <artifactId>ad-hoc-parent</artifactId>
    <groupId>com.recondo.reporting</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>adhoc-data</artifactId>
<packaging>pom</packaging>
<modules>
    <module>adhoc-data-base-models</module>
</modules>

<properties>
    <java.version>1.8</java.version>
    <spring.boot.repackage.skip>true</spring.boot.repackage.skip>
</properties>

<dependencies>
    <dependency>
        <groupId>com.recondo.reporting</groupId>
        <artifactId>adhoc-data-base-models</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

<properties>
    <java.version>1.8</java.version>
    <spring.boot.repackage.skip>true</spring.boot.repackage.skip>
</properties>

under the data module what i wanted to do is create sub-modules to organize code. here is an example of a module i created for storing base models that each report could extend from:

    <parent>
    <artifactId>adhoc-data</artifactId>
    <groupId>com.recondo.reporting</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>adhoc-data-base-models</artifactId>

<properties>
    <java.version>1.8</java.version>
    <spring.boot.repackage.skip>true</spring.boot.repackage.skip>
</properties>

when i try and build this project i get an error that there is a cyclical dependency between adhoc-data-base-model and adhock-data

The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='com.recondo.reporting:adhoc-data:0.0.1-SNAPSHOT'}' and 'Vertex{label='com.recondo.reporting:adhoc-data-base-models:0.0.1-SNAPSHOT'}' introduces to cycle in the graph com.recondo.reporting:adhoc-data-base-models:0.0.1-SNAPSHOT --> com.recondo.reporting:adhoc-data:0.0.1-SNAPSHOT --> com.recondo.reporting:adhoc-data-base-models:0.0.1-SNAPSHOT -> [Help 1]

which i read in possible solution which made sense, but when i removed the dependency in the adhoc-data pom as the link suggests, i get this error:

[ERROR] Failed to execute goal on project ad-hoc-web: Could not resolve dependencies for project com.recondo.reporting:ad-hoc-web:jar:0.0.1-SNAPSHOT: Could not find artifact com.recondo.reporting:adhoc-data:jar:0.0.1-SNAPSHOT -> [Help 1] which makes sense maybe... i am packaging the data module as a pom because that's how the parent module was packaged with child modules....

how should i solve this/ construct multi module maven projects to handle more than one level of dependencies?

StillLearningToCode
  • 2,271
  • 4
  • 27
  • 46

1 Answers1

0

The first which is wrong I see in your picture is you adhoc-data module which contains a src folder. The adhoc-data module is a parent for it's child which has <packaging>pom</packaging>this means such a module has never code in it this mean there should never be a folder src at all in it.

The cyclic dependency results from the point that your pom of adhoc-data defines an dependency to:

<dependencies>
    <dependency>
        <groupId>com.recondo.reporting</groupId>
        <artifactId>adhoc-data-base-models</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

and also is a parent of the given module. This is simply wrong. First step is to remove the above dependency from adhoc-data pom file.

Furthermore there are other smells in your build based on those properties <spring.boot.repackage.skip>true</spring.boot.repackage.skip>...

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • i have removed the dependency and the repackage skip... no change in result. it would really help me more if you could explain how it should look rather than what smells or not. i clearly don't know what i'm doing here. that's why i posted the question. I did research other resources ad if you know of one that has an explanation came up with only single level dependencies. – StillLearningToCode May 09 '19 at 00:44
  • Please make an example project on Github etc. that would really help apart from that you should try to do some research and read documentations.... – khmarbaise May 09 '19 at 05:32