Ramazan Cinardere
Ramazan Cinardere

Reputation: 133

Maven project inheritance: Cannot resolve imports from parent project

I set up two (maven) projects, the first contains simple Java-Classes. The first project should act as a master/parent project over (yet only one) many project.

I need that the second project, should be able to use some classes from the parent project.

What I have tried yet.

1.) I have installed the first project with mvn install 2.) Declared the first-project as parent in the pom of the second-project. <parent>...</parent>

In the second project, try to import classes from first project, failes. I'm not able to use classes from the first-project.

Let me show some snippets of both pom:

1) First pom:

<groupId>com.sample</groupId>
<artifactId>parent</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>

2.) Second pom.xml:

<parent>
    <groupId>com.sample</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.1</version>
</parent>

Is it possible, to use components from parent pom/project??

Upvotes: 1

Views: 2887

Answers (1)

Fabien
Fabien

Reputation: 376

Your question was already answered there : Maven include parent classes

You need to understand the concepts behind a multi modules project and how the maven dependencies management works. A lot of documentation is available, for example : https://www.baeldung.com/maven-multi-module

Technically you can do this by changing the packaging of the parent pom from pom to jar, but there cannot be a good reason to do what you want. The parent module is not there to be a provider of classes for the children modules. Just move your classes from the parent module into another module, and add a dependency to this module into your second pom.xml.

Upvotes: 1

Related Questions