6

So basically, I have a multi-module project such as

- ProjectA
  |- Module1
  |- Module2

The relevant part (I believe) pom.xml for ProjectA is:

<modelVersion>4.0.0</modelVersion>
<groupId>com.companyName</groupId>
<artifactId>ProjectA</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.1.RELEASE</version>
</parent>

<modules>
    <module>Module1</module>
    <module>Module2</module>
</modules>

And pom.xml for Module1 is:

<parent>
    <groupId>com.companyName</groupId>
    <artifactId>ProjectA</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>Module1</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>

And the pom.xml for the Module2 which depends on Module1 is as follows:

<parent>
    <groupId>com.companyName</groupId>
    <artifactId>ProjectA</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Module2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
    <dependency>
        <groupId>com.companyName</groupId>
        <artifactId>Module1</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    ...
</dependencies>

I can build and install Module1 just fine. I can import classes from it in Module2, yet I cannot compile Module2 with: Could not find artifact com.companyName:ProjectA:pom:0.0.1-SNAPSHOT

In a same way, I am building yet another project, ProjectB which will have Module3. In Module3 pom.xml:

<dependency>
    <groupId>com.companyName.ProjectA</groupId>
    <artifactId>Module1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

But yet, I cannot import it in my .java files, as com.companyName.ProjectA is not available, IntelliJ warns me. What am I doing wrong? I have tried almost every configuration in related multi-module project questions. Thanks!

Update: The console output has changed to:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/user/workspace/project-name/Module2/src/main/java/com/companyName/ProjectA/Module2/users/UsersDAO.java:[3,39] package com.companyName.ProjectA.Module1 does not exist
[ERROR] /Users/user/workspace/project-name/Module2/src/main/java/com/companyName/ProjectA/Module2/users/UsersDAO.java:[9,6] cannot find symbol...

Update: Interestingly, removing:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

from parent project (ProjectA) makes the project buildable again. However, I need it (for obvious reasons) Is there a workaround for this? Thanks!

Hasan Can Saral
  • 2,950
  • 5
  • 43
  • 78
  • did you confirm the presence in `~/.m2/repository` after building `Module1` ? – Naman Dec 13 '16 at 10:47
  • @nullpointer Yes and I can show it as dependency for yet another project, say `ProjectB`, but I cannot import it in my .java files in `Module3` of `ProjectB`. – Hasan Can Saral Dec 13 '16 at 10:55
  • What do you mean *show it as dependency* ? It sounds something like, you can always write some piece of code, but unless you compile it, you won't know what's wrong in it. – Naman Dec 13 '16 at 11:05
  • I am sorry, should have been clearer. I can write it into `pom.xml` without IntelliJ yelling at me not to (marking it as red, etc.), but then I cannot us classes from it with `import`. – Hasan Can Saral Dec 13 '16 at 11:07
  • If you are certain that `Module1.jar` is present in `~/.m2/repository` and you are not able to import it in Module2 or projectB. Please share the entire console output for the build which fails for either Module2 or ProjectB. – Naman Dec 13 '16 at 11:11
  • 1
    I am 100% certain as the file is sitting just there. I am updating my question with the full console output in a moment. – Hasan Can Saral Dec 13 '16 at 11:13
  • @nullpointer I have updated my question, but not with some more console output, but with a potential solution. I would appreciate further help. Thanks! – Hasan Can Saral Dec 13 '16 at 14:10
  • Well the update was way out of what the existing question was. Anyway glad that it is solved. Please make sure you share relevant details while posting in future. :) – Naman Dec 13 '16 at 18:18
  • this simple solution helped me https://discuss.circleci.com/t/maven-multi-module-project-reactor-install-goal-does-not-see-dependencies-that-have-been-built-a-while-ago/29051 – Zwakele Mgabhi May 29 '20 at 16:51

1 Answers1

8

Both (or all) projects are Spring Boot projects. Which aren't regular jars but executable jars with a different structure. You shouldn't include a Spring Boot jar in another Spring Boot jar.

How to cope with this is explained in a section in the reference guide.

Basically, you need to explicitly configure 2 artifacts for Module1

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <classifier>exec</classifier>
            </configuration>
        </plugin>
    </plugins>
</build>

Or if Module1 isn't even an executable application but only a library, don't use the Spring Boot Maven plugin for that.

Naman
  • 27,789
  • 26
  • 218
  • 353
M. Deinum
  • 115,695
  • 22
  • 220
  • 224