api重复引用导致的诡异问题排查
api重复引用导致的诡异问题排查
最近一个项目上线前开发环境、测试环境都能正常打包并运行。然而到了准生产环境和生产环境则报一些诡异的错误信息:
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project xxx: Compilation failure: Compilation failure:
[ERROR] /data/release/xxx/xxx/src/main/java/com/xxx/testmodel/util/ZipRsaCiph.java:[19,15] BASE64Decoder is internal proprietary API and may be removed in a future release
[ERROR] /data/release/xxx/xxx/src/main/java/com/xxx/testmodel/util/ZipRsaCiph.java:[19,15] BASE64Decoder is internal proprietary API and may be removed in a future release
[ERROR] /data/release/xxx/xxx/src/main/java/com/xxx/testmodel/util/ZipRsaCiph.java:[19,15] BASE64Decoder is internal proprietary API and may be removed in a future release
[ERROR] /data/release/xxx/xxx/src/main/java/com/xxx/testmodel/util/ZipRsaCiph.java:[19,15] BASE64Decoder is internal proprietary API and may be removed in a future release
[ERROR] /data/release/xxx/xxx/src/main/java/com/xxx/testmodel/util/ZipRsaCiph.java:[64,9] BASE64Decoder is internal proprietary API and may be removed in a future release
[ERROR] /data/release/xxx/xxx/src/main/java/com/xxx/testmodel/aop/Author.java:[95,90] error: cannot find symbol
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
咋一看莫名其妙,代码怎么找也找不到问题所在。查看代码修改部分,发现是重新引入了一个新的api。
通过mvn dependency:tree
发现,同时引用了 test-api:jar:2.0.0 和 test-api:jar:3.12.0 两个版本的api。
而通过mvn dependency:analyze
查看的结果为:
[WARNING] Used undeclared dependencies found:
[WARNING] com.xxx.auth:xxx-api:jar:2.0.0:compile
[WARNING] Unused declared dependencies found:
[WARNING] com.xxx.auth:xxx-api:jar:3.12.0:compile
发现并没有引用新的api。
Used undeclared dependencies
:指那些在项目中直接使用到的,但没有在POM中配置的依赖。
Unused declared dependencies
:供我们参考,这表示那些我们配置了,但并未直接使用的依赖。
后来分析发现是有个第三方 api 引用了相同的api,从而导致这一诡异问题的出现。因而在引用api前可通过:
mvn dependency:tree
和 mvn dependency:analyze
看是否存在重复引用的api,如果存在重复引用的情况可将不需要的版本api排除掉即可。
<dependency>
<groupId>xxx</groupId>
<artifactId>xxx-api</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>test</groupId>
<artifactId>test-api</artifactId>
</exclusion>
</exclusions>
</dependency>
扫描公众号,关注更多信息
---------------------------------------------------------------------------------我是分割线--------------------------------------------------------------------------to be a better me, talk is cheap show me the code
版权所有,转载请注明原文链接。
文中有不妥或者错误的地方还望指出,以免误人子弟。如果觉得本文对你有所帮助不妨【推荐】一下!如果你有更好的建议,可以给我留言讨论,共同进步!
再次感谢您耐心的读完本篇文章。
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?