Search code examples
springmavenmulti-module

Maven - multi module application - problem with clean install



I have a multi modular application,
I need to import some classes from the parent module (they are similar for all modules)
So as intellij prompts, I made a dependency to the parent module
(this is my first multi module app)

The problem is that when I do

mvn clean install -Dmaven.test.skip=true 

I have a build failure.
It seems that maven is seeking my parent project from the dependency online, where obviously it doesn't exist, and it should look locally... I think

Actually the applications can be build, and run, but I cannot make a package, I cannot install it...

How can I resolve it?
here is some code:

pom.xml for parent:

   <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.3</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>eu.mrndesign.matned</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
    <module>../credit</module>
    <module>../client</module>
    <module>../product</module>
</modules>

<name>parent</name>
<description>Description</description>
<packaging>pom</packaging>
        ...
</dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${project.parent.version}</version>
            </plugin>
        </plugins>
    </build>

</project>

One of the children pom (they are 3 and they look almost the same):

<modelVersion>4.0.0</modelVersion>
<dependencies>
    <dependency>
        <groupId>eu.mrndesign.matned</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

<parent>
    <groupId>eu.mrndesign.matned</groupId>
    <artifactId>parent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../parent</relativePath>
</parent>

<artifactId>product</artifactId>
<name>product</name>
<description>Product module for create credit application</description>
<properties>
    <java.version>11</java.version>
</properties>

And here is the message when clean install:

[INFO] ---------------------< eu.mrndesign.matned:credit >---------------------
[INFO] Building credit 1.0-SNAPSHOT                                       [2/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for parent 1.0-SNAPSHOT:
[INFO] 
[INFO] parent ............................................. SUCCESS [  0.857 s]
[INFO] credit ............................................. FAILURE [  0.133 s]
[INFO] client ............................................. SKIPPED
[INFO] product ............................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.237 s
[INFO] Finished at: 2021-04-09T03:53:09+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project credit: Could not resolve dependencies for project eu.mrndesign.matned:credit:jar:1.0-SNAPSHOT: Failure to find eu.mrndesign.matned:parent:jar:1.0-SNAPSHOT in https://repo.spring.io/release was cached in the local repository, resolution will not be reattempted until the update interval of spring-releases has elapsed or updates are forced -> [Help 1]
[ERROR] 

Solution

  • The parent cannot contain code and therefore cannot be used as a dependency.

    Put your classes into a module and use that module as dependency in other modules.