File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Ant, Maven and Other Build Tools and the fly likes Transitive Dependencies at the compile time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Transitive Dependencies at the compile time " Watch "Transitive Dependencies at the compile time " New topic

Transitive Dependencies at the compile time

Ravi Bansal
Ranch Hand

Joined: Aug 18, 2008
Posts: 86

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.

SCJP 5.0 94%
lokesh sree
Ranch Hand

Joined: Oct 27, 2009
Posts: 100

Looks like you can actually exclude transitive dependencies.. You can look at this and see if it helps.

Ravi Bansal
Ranch Hand

Joined: Aug 18, 2008
Posts: 86
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

Joined: May 14, 2008
Posts: 5852

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.

JBoss In Action
I agree. Here's the link:
subject: Transitive Dependencies at the compile time
jQuery in Action, 3rd edition