eyeix
V2EX  ›  问与答

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

  •  
  •   eyeix · Dec 12, 2020 · 1442 views
    This topic created in 1988 days ago, the information mentioned may be changed or developed.

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

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

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

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

    3 replies    2020-12-12 14:44:07 +08:00
    Duolingo
        1
    Duolingo  
       Dec 12, 2020 via Android
    scope compile
    auin
        2
    auin  
       Dec 12, 2020
    请使用:
    <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  
       Dec 12, 2020
    scope
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2832 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 14:54 · PVG 22:54 · LAX 07:54 · JFK 10:54
    ♥ Do have faith in what you're doing.