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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With