V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
lrvinye
V2EX  ›  问与答

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

  •  
  •   lrvinye · 2020-12-12 11:58:07 +08:00 · 1005 次点击
    这是一个创建于 1252 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

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

    3 条回复    2020-12-12 14:44:07 +08:00
    codingadog
        1
    codingadog  
       2020-12-12 12:51:05 +08:00 via Android
    scope compile
    liuxey
        2
    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
        3
    daimubai  
       2020-12-12 14:44:07 +08:00
    scope
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4728 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 04:05 · PVG 12:05 · LAX 21:05 · JFK 00:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.