Maven编译错误 [英] Strange compilation error with Maven

查看:174
本文介绍了Maven编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目A依赖于项目B,它依赖于项目C.项目C依赖于Hibernate(更确切地说是org.hibernate:hibernate-core:3.6.8.Final)。项目B不依赖于hibernate工件。但是,项目A依赖于此工件,但仅用于单元测试,因此我使用测试范围。当我尝试构建A,项目C和B正确构建和安装,但我在编译期间遇到以下错误:

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:


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

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编译成功,所以它可以找到上述类。
但是在这里,似乎在编译期间找不到类文件。我认为也许测试范围的Hibernate依赖可以取消C的Hibernate依赖项?但是,我不知道。

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.

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

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

感谢您的帮助

推荐答案

这是一个编译器错误和代码中的错误。

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

在您身边:

您覆盖了暂时的hibernate依赖项的范围,

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

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

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.

在编译器的一边:

这在技术上只是吐出与任何其他编译器生成的错误/警告。然而,有人错过了编译器端的东西,所以编译器崩溃,而不是附加到警告列表。我建议更新到最新的JDK,请重试,如果仍然不工作报告错误。

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.

这篇关于Maven编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆