Maven 的奇怪编译错误

发布于 2024-12-27 09:30:11 字数 872 浏览 0 评论 0原文

我有一个项目 A,它依赖于项目 B,而项目 B 又依赖于项目 C。项目 C 依赖于 Hibernate(更准确地说是 org.hibernate:hibernate-core:3.6.8.Final)。项目 B 不依赖于休眠工件。但是,项目 A 依赖于这个工件,但仅用于单元测试,所以我使用测试范围。当我尝试构建 A 时,项目 C 和 B 已正确构建并安装,但在 A 编译期间出现以下错误:

执行javac失败,但无法解析错误: myPackage\MyClass.class(myPackage:MyClass.class): 警告: 找不到 类型中的注释方法“value()” 'org.hibernate.annotations.Cascade':类文件 org.hibernate.annotations.Cascade not found 发生异常 在编译器中(1.6.0_27)。请向 Java 开发人员提交错误 检查后连接(http://java.sun.com/webapps/bugreport) 重复的错误游行。包括您的程序和以下内容 报告中的诊断。谢谢。 com.sun.tools.javac.code.Symbol$CompletionFailure:类文件 org.hibernate.annotations.CascadeType 未找到

我确切地说 MyClass 属于项目 C 并导入 org.hibernate.annotations.Cascade。 C 编译成功,因此可以找到该类。 但是这里,A编译的时候好像找不到class文件。我想也许测试范围内对 Hibernate 的依赖可能会取消 C 对 Hibernate 的依赖?但是,我不知道。

另外,如果我将项目 A 中的依赖范围从测试更改为编译,问题就会消失。

感谢您的帮助

I have a project A that depends on project B that depends on project C. Project C depends on Hibernate (more precisely org.hibernate:hibernate-core:3.6.8.Final). Project B doesn't depend on the hibernate artifact. But, project A depends on this artifact but only for unit tests, so I use test scope. When I try to build A, projects C and B are correctly built and installed but I get the following error during A compilation:

Failure executing javac, but could not parse the error:
myPackage\MyClass.class(myPackage:MyClass.class): warning: Cannot find
annotation method 'value()' in type
'org.hibernate.annotations.Cascade': class file for
org.hibernate.annotations.Cascade not found An exception has occurred
in the compiler (1.6.0_27). Please file a bug at the Java Developer
Connection (http://java.sun.com/webapps/bugreport) after checking the
Bug Parade for duplicates. Include your program and the following
diagnostic in your report. Thank you.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for
org.hibernate.annotations.CascadeType not found

I precise that MyClass belongs to project C and imports org.hibernate.annotations.Cascade. And C compiles successfully so it can find the said class.
But here, it seems that the class file cannot be found during A compilation. I thought that maybe the test-scoped dependency on Hibernate may cancel the Hibernate dependency of C? But, I have no idea.

Also, if I change the scope of the dependency in project A from test to compile, the problem disappears.

Thanks for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扶醉桌前 2025-01-03 09:30:11

这既是编译器错误,也是代码中的错误。

在您这边:

您正在覆盖瞬态休眠依赖项的范围,因此它在编译时不可用,仅在测试时可用。

项目 C 中的 MyClass 中使用的注释在运行时可用(否则 hibernate 在运行项目时将无法引用它们)。这意味着当您编译时,javac 需要能够加载这些注释,但它找不到它们。

在编译器方面:从

技术上讲,这应该与任何其他编译器生成的错误/警告一起吐出。然而,有人遗漏了编译器方面的某些内容,因此编译器崩溃了,而不是附加到警告列表中。我建议更新到最新的 JDK,再试一次,如果仍然不起作用,请报告错误。

It's both a compiler bug and a bug in your code.

On your side:

You're overriding the scope of the transient hibernate dependency so it isn't available at compile time, only at test time.

The annotations being used in MyClass in project C are available at runtime (otherwise hibernate wouldn't be able to reference them when running your project). This means that when you compile, javac needs to be able to load those annotations but it can't find them.

On the compiler's side side:

This should technically just be spit out with any other compiler generated errors/warnings. However, somebody missed something on the compiler's side so the compiler is crashing instead of appending to the list of warnings. I would recommend updating to the latest JDK, try again, and if it still doesn't work report a bug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文