File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transitive Dependencies at the compile time

 
Ravi Bansal
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am new to maven . I have a project which is using Maven 3 and Jdk 6 . I am not able to understand why maven is trying to look for the transitive dependency at the compile time itself.
For example , I have a Project P which has dependency A (JAR file) and A Jar is using some classes from B Jar , means A is dependent on B.
That implies that P is transitively dependent on B. (P -->A-->B)
Now when Project P is being compiled (mvn compile ) , its giving Compile time errors saying that some of the symbols are not resolved (that is classes from B JAR are not available ).

My question is why this issue is coming at the compile time itself , this should be the run time Error ?.
Is maven smart enough to read the dependent JAR's bytecode (JAR A) and resolve its dependencies (JAR B) at the compile time of Project P itself.
 
lokesh sree
Ranch Hand
Posts: 100
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Looks like you can actually exclude transitive dependencies.. You can look at this http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html and see if it helps.
 
Ravi Bansal
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Lokesh.

But excluding the dependency is not an issue , Exclusion will only help in not having the dependency in the final EAR
The question here is why its trying to look for compilation issues in the JAR ?

It should have thrown the ClassNotFoundException at the run time rather than report ing this as compilation failure. ?

 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Transitive dependencies are included at compile time because they might be needed to support deeply nested class hierarchies. For example, class C extends B, class B extends A. Each class is in a separate (c.jar, b.jar and a.jar). Your app creates another class that extends class C, so you place c.jar in your dependencies. But that is insufficient for the compiler to determine what your class looks like. Thus Maven includes the transitive dependencies to "fix" this issue. (Personally, I would preferred that in this case that Maven would require you to include a.jar, b.jar and c.jar in your dependency list.)

Though reading you post again, it doesn't look like you are getting a Maven error (hard to say for sure since you didn't post the exact error message you are seeing, paraphrasing error message is always a bad idea) but rather a compiler error message. The above still applies - the compiler needs all of the superclass information to construct object layouts.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic