从使用我的库的其他模块中排除依赖项

Excluding a dependency from other modules that use my library

我正在编写一个使用 SLF4J 进行日志记录的库。该库包含 类 和 Main() 方法,因此我想在类路径中包含一些 SLF4J 的实现,例如 Logback。

但我不想 "contaminate" 其他库将我的库添加为依赖项(意思是,我不希望它们将 Logback 作为依赖项传递)。所以我想告诉Maven:"Add Logback as a dependency but don't add it as a transitive dependency in other models using this library"。

有什么办法吗?

我想你正在寻找 optional dependencies