“optional” dependency with scope “provided” in Maven

前端 未结 1 1196
孤城傲影
孤城傲影 2020-12-10 00:40

Maven is a bit over my head sometimes... I have created a library which has an optional dependency on slf4j and on log4j. By optional, I mean:

  • My library needs
相关标签:
1条回答
  • 2020-12-10 01:07

    Did you check this documentation. It describes your use case very good. Marking dependencies as optional will not resolve them as transitive dependencies in the application which use your library (even if the scope is compile).

    In difference to <scope>provided</scope> which is used for required dependencies which will be provided by the runtime environment an <optional>true</optional> dependency is not necessarily meant to be required (The idea is that some of the dependencies are only used for certain features in the project, and will not be needed if that feature isn't used.).

    If a project which uses your library will use any functionallity provided by the optional dependencies the project has to declare these dependencies for their own.

    As your configuration seems to be correct for me I do not know the reason what probles occur. Maybe your optional dependencies get resolved by other libraries in versions you do not expect. That of course might cause problems.

    0 讨论(0)
提交回复
热议问题