我有一个项目 A,它依赖于项目 B,项目 B 又依赖于项目 C。项目 C 依赖于 Hibernate(更准确地说是 org.hibernate:hibernate-core:3.6.8.Final)。项目 B 不依赖于 hibernate Artifact 。但是,项目 A 依赖于这个 Artifact ,但仅用于单元测试,所以我使用测试范围。当我尝试构建 A 时,项目 C 和 B 已正确构建并安装,但在 A 编译期间出现以下错误:
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
我准确地说MyClass属于项目C并导入了org.hibernate.annotations.Cascade。 C 编译成功,因此可以找到该类。 但是这里,A编译的时候好像找不到class文件。我想也许测试范围内对 Hibernate 的依赖可能会取消 C 对 Hibernate 的依赖?但是,我不知道。
此外,如果我将项目 A 中的依赖范围从测试更改为编译,问题就会消失。
感谢您的帮助
最佳答案
这既是编译器错误,也是代码中的错误。
在你身边:
您将覆盖 transient hibernate 依赖项的范围,因此它在编译时不可用,仅在测试时可用。
项目 C 中的 MyClass 中使用的注释在运行时可用(否则 hibernate 在运行项目时将无法引用它们)。这意味着当您编译时,javac 需要能够加载这些注释,但它找不到它们。
在编译器方面:
从技术上讲,这应该与任何其他编译器生成的错误/警告一起吐出。然而,有人遗漏了编译器方面的某些内容,因此编译器崩溃了,而不是附加到警告列表中。我建议更新到最新的 JDK,再试一次,如果仍然不起作用,请报告错误。
关于java - Maven 的奇怪编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8881404/