i'm building this app composed of several microservices , using common and reusable classes all shared in a package of name commons , which at the same time is imported on each and every microservice needed of using whatever the cladsses common shares.
For some reason one of the microservices(microproducts)was needed of generating a new jar , but on the process i got warning of not finding first the common library in its pom and second , throws me an error , all this when im deploying on docker images each and every of the micro's.
my work sapce structure with all the components including common and all else microservices would be like this :
![enter image description here](https://i.stack.imgur.com/q972z.png)
Lets say my common library would be designed like this :
<?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.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.commons</groupId>
<artifactId>commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>commons</name>
<description>Demo project for commons</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--PARA EL MANEJO DE JPA-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- SPRING REST-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<!--TEST-->
<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>
<!--INACTIVANDOSE EL PLUGIN AL SER ESTO SOLO UNA LIBRERIA -->
<build>
</build>
</project>
Being its main class disabled due to ist function of shareable resource:
package com.commons;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class CommonsApplication {
}
Then on one of my microservices(microproducts) i do first import that common library on its pom and second in its main class i scan all components , entities, base packages the class needed coming from common in order to work
MICROPRODUCTS POM
<?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.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.microproducts</groupId>
<artifactId>microproducts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>microproducts</name>
<description>Demo project for microproducts</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
</properties>
<dependencies>
<!--LIBRERIA COMUN DE COMMONS CREADA-->
<dependency>
<groupId>com.commons</groupId>
<artifactId>commons</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<!-- SWAGGER 2-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>
<!-- SWAGGER UI-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- JPA-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- SPRING REST-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<!-- SPRING WEB-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- EUREKA CLIENT-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- SLEUTH TRACE CONEXION-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<!-- ZIPKIN-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<!-- DEPENDENCIA CONNECTORA DE RABBIT MQ PARA EL MANEJO DE RESPUESTAS Y LOGS SOBRE
TRAZAS EN ZIPKING SERVER-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<version>2.2.11.RELEASE</version>
</dependency>
<!--DEVTOOLS-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- CONNEXION A MYSQL-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- TEST-->
<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>
</plugins>
</build>
</project>
As you can see the common library is imported as first
then the main class got designed in this way:
package com.microproducts;
import com.microproducts.repositories.ImgSubTypeRepository;
import com.microproducts.repositories.ProductRepository;
import com.microproducts.repositories.RenterRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@EnableEurekaClient
@SpringBootApplication
@ComponentScan({"com.commons.dtos","com.commons.exceptions","com.commons.responses","com.commons.repositories","com.commons.responses"})
@EntityScan("com.commons.entities")
@ComponentScan(basePackageClasses = {ProductRepository.class, RenterRepository.class, ImgSubTypeRepository.class})
public class MicroproductsApplication {
public static void main(String[] args) {
SpringApplication.run(MicroproductsApplication.class, args);
}
}
Any idea about why this behave of not letting me to build a jar cause of not "finding" my common jar previously imported?
![enter image description here](https://i.stack.imgur.com/Z5JP3.png)