Dhrubo
Dhrubo

Reputation: 715

Intellij Spring maven install error "package does not exist"

Intellij version : Community 2019.2.3 Maven : 3.6.2 Spring : 2.2.0

I am trying to create a very simple Spring maven project with two sub-modules (one independent and another one dependent on independent one).

Root module - testmultimodule Independent module - independent Dependent module - dependent

testmultimodule pom.xml has all Spring related declaration and module definition

<modules>
    <module>independent</module>
    <module>dependant</module>
</modules>

Independent poom.xml is simplest and . only has parent maven declaration

<parent>
    <artifactId>testmultimodule</artifactId>
    <groupId>in.org.app</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

dependent module pom.xml has the dependency declaration as below to independent module

   <dependencies>
        <dependency>
            <groupId>in.org.app</groupId>
            <artifactId>independent</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

I have created a Test class under dependent module and using a User object from independent module. Initially, without the above dependency declaration, asa usual there was compilcation error. As soon as I add the dependency and builld the project within Intellij IDE with the option "Build Prooject" option from "Build" menu, it successfully builds.

However, if I try to use Maven install option within Intellij right side window option. It always fails stating Error:(3,33) java: package in.org.app.independent.bo does not exist .

I am providing the GitHub URL for the test project , if you want to take a look and test by yourself.

GIT URL:

https://github.com/DhruboB/testmultimodule

I have tried all sort of tweaking found in internet so far e.g. clearing Intellij Cache & restarting, mvn -U clean install, mvn scope verification, proxy etc.

Any further idea to resolve this? I need to solve this in the Community version of Intellij.

Upvotes: 0

Views: 799

Answers (1)

M. Deinum
M. Deinum

Reputation: 124441

Your parent project includes the definition for the spring-boot-maven-plugin. This leads to each project defining this as a parent to be repacked to an executable JAR by this plugin. This repackaged JAR isn't useable as a dependency in another project.

Either you need to change the configuration of the spring-boot-maven-plugin for the project you want to use as a dependency. This is explained here in the Spring Boot Reference Guide. You now basically have 2 jars from this project, one plain and one executable.

If you don't need that project to be an executable JAR file then just move the spring-boot-maven-plugin to the project that needs to be. All other projects will no be basic JAR files again.

See also How to add a dependency to a Spring Boot Jar in another project?

Upvotes: 2

Related Questions