在公共项目开发了common模块,其中包含了发钉钉消息、时间处理等多种公共方法,现在想要发布到maven仓库给其他应用使用。
其他应用使用过程中发现,引入common模块的依赖后还需要单独引用common内部的其他依赖。
client如果要使用发消息模块的能力,需要引入如下依赖:
pom.xml:
com.dingtalk.open dingtalk-openapi-sdk xxx com.alibaba.logistics logistics-infra-common 1.0.1-SNAPSHOT
这样使用存在两个问题:
1.client需要手动引入common内部使用的依赖,没有起到统一管理的效果。
2.common升级内部依赖client也要跟着升级,否则可能出现低版本使用高版本依赖的方法,比如:ObjectUtils.allNull() 方法就在 commons-lang3 低版本就没有。
那为什么不直接将common模块所需要依赖都打进去呢?
pom.xml:
maven-assembly-plugin false assembly.xml org.apache.maven.plugins maven-source-plugin 3.0.1 maven-source-plugin attach-sources jar
assembly.xml:
common.jar jar false ${project.build.directory}/classes / **** / false javax.annotation:javax.annotation-api log4j:log4j org.slf4j:slf4j-api org.slf4j:jul-to-slf4j ch.qos.logback:logback-classic ch.qos.logback:logback-core org.apache.logging.log4j:log4j-to-slf4j org.apache.logging.log4j:log4j-api org.projectlombok:lombok org.springframework:spring-aop org.springframework:spring-beans org.springframework.boot:spring-boot org.springframework.boot:spring-boot-autoconfigure org.springframework.boot:spring-boot-starter org.springframework.boot:spring-boot-starter-logging org.springframework:spring-context org.springframework:spring-core org.springframework:spring-expression org.springframework:spring-jcl org.yaml:snakeyaml
依赖展示:
经过上述的打包优化后,打出的common包已经很轻量化了,client使用只需要引入common本身即可。
com.alibaba.logistics logistics-infra-common 1.0.1-SNAPSHOT



