Adding Spring boot application as a dependency to another spring boot application
The Spring Boot Maven and Gradle plugins both package our application as executable JARs – such a file can't be used in another project since class files are put into BOOT-INF/classes. This is not a bug, but a feature.
In order to share classes with another project, the best approach to take is to create a separate jar containing shared classes, then make it a dependency of all modules that rely on them.
But if that isn't possible, we can configure the plugin to generate a separate jar that can be used as a dependency.
Suppose we have two projects
1- general_definitions_app
2- cutstomer_service_app
we want to add "general_definitions_app" as a dependency to "cutstomer_service_app"
Steps:
1- open general_definitions_app , then open the pom.xml file
2- serach for the plugin "spring-boot-maven-plugin" and modify it to be
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
we added <configuration>
<classifier>exec</classifier>
</configuration>
to generate separate jar file with suffix "-exec"
3- click save
4- using CMD , go to the location of the "general_definitions_app"
issue this command:
mvn clean
mvn install
this will install two separate jars in the local repos ".m2" folder in you machine, the first one is for the spring boot app , the second one will be used as dependencies in other projects
5- open the "cutstomer_service_app" , then open the pom.xml file
6- add dependencies. Example:
<dependency>
<groupId>org.dhaman.opr</groupId>
<artifactId>opr-gen-definitions</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
7- update the depencencies
Comments