0

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.

Dhrubo
  • 705
  • 1
  • 14
  • 33
  • Both your projects are Spring Boot projects, you cannot use a Spring Boot enhanced jar as a dependency in another project. You will have to create a plain jar for the dependency use, this is also mentioned in the [Spring Boot Reference Guide](https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-create-an-additional-executable-jar). Move the `spring-boot-maven-plugin` to the project you want to actually package as an executable jar (or follow the guide to release 2 jar files 1 executanle 1 plain as use for a dpendency). – M. Deinum Oct 14 '19 at 13:20
  • Bang on, Completely logical, thank you very much @M.Deinum , you could have used ANswer button, so I could accept. – Dhrubo Oct 14 '19 at 13:45
  • Apart from what has been mentioned before Spring Boot 2.2.0 does not yet exist ...2.2.0.RC1 exists..furthermore I've made a pull request against your repo and fixed your configuration...Better use released versions like 2.1.8.RELEASE and cleaned up your configuration. Building does not work on command line cause you have compile issues...The rest looks good so far ...Test building on plain command line ... – khmarbaise Oct 14 '19 at 13:48
  • @khmarbaise I already fixed and updated the repo as suggested by M.Deinum. Anyways, thank you for your opinion too. – Dhrubo Oct 14 '19 at 14:31

1 Answers1

2

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?

M. Deinum
  • 115,695
  • 22
  • 220
  • 224