Strange compilation error with Maven

I have project A which depends on project B which depends on project C. Project C depends on Hibernate (more precisely, org.hibernate: hibernate-core: 3.6.8.Final). Project B does not depend on the hibernation artifact. But project A depends on this artifact, but only for unit tests, so I am using testing scope. When I try to build A, projects C and B are correctly built and installed, but during compilation of A I get the following error:

Could not execute javac but could not parse 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 occurred in the compiler (1.6.0_27). Please file a bug in Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Error parameter for duplicates. Include your program and the following diagnostics in your report. Thank. com.sun.tools.javac.code.Symbol $ CompletionFailure: Class file for org.hibernate.annotations.CascadeType not found

I point out exactly that MyClass belongs to the C project and imports org.hibernate.annotations.Cascade. And C compiles successfully, so it can find the specified class. But here it seems that the class file cannot be found at compile time A. I thought that maybe the test scope dependency on Hibernate could break Hibernate's dependency on C? But I have no idea.

Also, if I change the scope of the dependency in project A from the compilation test, the problem goes away.

thanks for the help

+2


source to share


1 answer


This is both a compiler error and a bug in your code.

From your side:

You are overriding the transient hibernation scope so it is not available at compile time, only during testing.



The annotations used in MyClass in a C project are available at runtime (otherwise hibernate will not be able to reference them when your project starts). This means that when compiling, javac should be able to load these annotations, but cannot find them.

From the compiler side:

This should technically just splash out with any other compiler-generated errors / warnings. However, someone missed something on the compiler side, so the compiler is crashing, not adding to the warning list. I would recommend updating to the latest JDK, try again and if it still doesn't work please report a bug.

+3


source







All Articles