I’m working on a project with a library module that has about 10 submodules.
For the application project the developer asked us to find a way so that they can import only one dependency, instead of the requested 10. Let’s use as an example the dependency of log4j: I need only to include one not all the sub-dependencies.
How can I achieve this kind of structure for my library?
Advertisement
Answer
I believe this can be accomplished by making use of Maven’s transitive dependencies. Essentially, you will create a new project which then has dependencies on all the other dependencies you want to group and provide to another application. You can then add the new project as a dependency in the application’s POM, bringing in all the transitive dependencies.
This is kind of similar to the Spring Boot Starter dependencies, which package a few Spring dependencies together to make it quick to get started with Spring Boot. See https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-starters/spring-boot-starter/build.gradle