【问题标题】:Maven dependency not propagated to dependent projectMaven依赖未传播到依赖项目
【发布时间】:2020-04-12 23:08:43
【问题描述】:

我的 Eclipse 工作区中有两个 Maven 项目,datastoreservice

datastore 将 HSQLDB 作为 Maven 依赖项,范围为 compile

由于service 依赖于datastore,我已将datastore 添加为属性> Java 构建路径> 项目 中的必需项目。

但是,当我现在运行 service 时,我会得到一个用于 HSQLDB JDBC 驱动程序的 ClassNotFoundException(在从 service 调用的 datastore 的类之一中)。

如果我将 HSQLDB 作为依赖项添加到 service,一切都会正常运行 - 尽管我知道我不应该需要这个,因为范围为 compile 的 Maven 依赖项应该传播到依赖项目。

另外,我注意到servicepom.xml 不包含对datastore 的引用。

错误在哪里,如果有的话?

【问题讨论】:

    标签: eclipse maven dependencies


    【解决方案1】:

    Properties > Java Build Path > Projects 是一种 Eclipse 机制,不会传播 Maven 依赖项。为了使依赖项传播按预期工作,datastore 需要是 Maven 依赖项。

    使用 pom.xml 中的组 ID、工件 ID 和版本添加 datastore 作为 Maven 依赖项。之后,可以从 Properties > Java Build Path > Projects 中删除该项目。

    【讨论】:

    • 如果它不用于编译,我建议也使用<scope>runtime</scope>添加此依赖项
    猜你喜欢
    • 1970-01-01
    • 2018-10-20
    • 2017-09-18
    • 1970-01-01
    • 2013-02-17
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 2014-05-25
    相关资源
    最近更新 更多