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
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.