In my spring-boot
project there are two microservices, one config-server, and one naming server. It also has two modules which I am adding as a dependency in the microservices.
Below is the pom
of the commons-new
module which should be a dependency in my microservices.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.highpeak.tlp</groupId>
<artifactId>commons-new</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>commons-new</name>
<description>Contains common modules needed by all the microservices</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
And I am adding it as a dependency in my microservice.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.highpeak.tlp</groupId>
<artifactId>ybanq-auth-manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ybanq-auth-manager</name>
<description>Manages the authentication process with ybanq</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR4</spring-cloud.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.testSource>1.8</maven.compiler.testSource>
<maven.compiler.testTarget>1.8</maven.compiler.testTarget>
</properties>
<dependencies>
<dependency>
<groupId>com.highpeak.tlp</groupId>
<artifactId>commons-new</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.highpeak.tlp</groupId>
<artifactId>redis-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I try to build the microservice using the command mvn clean install
, it is throwing compiler-error
message.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ybanq-auth-manager: Compilation failure: Compilation failure:
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/controller/AuthController.java:[3,42] package com.highpeak.tlp.commons.exception does not exist
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/controller/AuthController.java:[4,37] package com.highpeak.tlp.commons.util does not exist
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/service/AuthManagerService.java:[3,42] package com.highpeak.tlp.commons.exception does not exist
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/service/AuthManagerService.java:[11,51] cannot find symbol
[ERROR] symbol: class DataException
[ERROR] location: interface com.highpeak.tlp.ybanqauthmanager.service.AuthManagerService
[ERROR] /Users/sandeshaj/Documents/Bitbucket/lawshram-payments/ybanq-auth-manager/src/main/java/com/highpeak/tlp/ybanqauthmanager/service/AuthManagerServiceImpl.java:[19,42] package com.highpeak.tlp.commons.exception does not exist
However, in IntelliJ editor those classes are accessible and Intellij is not showing the compiler error. But when I run the app in IntelliJ, it shows the same errors.
What is the mistake I am making? Since I added the module as dependency their classes should be available, right?
My system maven version is 3.5.4
.
2
Answers
Remove spring boot plugin from submodule (common-new).
I had similar issue, but with gradle and found this Unresolved Dependency on package in subproject
Unfortunately, I don’t know what is exact issue in “using” spring boot plugin in submodules/subprojects.
The Spring Boot plugin package up all dependency jars and pulls them into the jar your module builds. The structure of this jar is specifically for Spring Boot runnable applications and is not compatible with the normal jar structures, so you can’t use a Spring Boot Application jar as maven dependency jar.