maven 依赖如何只引入而不使用?

2020-12-12 11:58:07 +08:00
 lrvinye

RT,比如说 我想在项目的 core 包中, 封装 SpringContextHolder 这样一个操作 springbean 的工具类, 用来在项目的多个 springboot 应用中引入 core 依赖, 然后使用 SpringContextHolder 等其它封装好的公共类。

但是,在编写 SpringContextHolder 的时候又需要引入 springboot 的依赖 (不然没有 ApplicationContextAware 这样的接口类...之类的问题)

所有我的问题是如何在 core 的 pom 里面引入 springboot 的依赖, 而不使用(因为 core 不是个应用,只是编写了一些公共类), 我知道直接引入跑起来也没问题, 但是主要是为了让 core 不那么重。

是使用<scope>?或者<optional>?

1010 次点击
所在节点    问与答
3 条回复
codingadog
2020-12-12 12:51:05 +08:00
scope compile
liuxey
2020-12-12 13:23:24 +08:00
请使用:
<scope>provided</scope>

官方的解释:
This scope is used to mark dependencies that should be provided at runtime by JDK or a container, hence the name.

ref: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope
daimubai
2020-12-12 14:44:07 +08:00
scope

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/734740

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX