You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by aldana <al...@gmx.de> on 2007/12/25 17:06:47 UTC

maven2 way to hide transitive dependencies

hi,

in former eclipse times where everything got included by a build-path and
residing lib/ folder inclusions of libraries exploded. especially the
export=true option for all libraries lead to an inclusion nigthmare. 

example:
-project A got dependencies to libraries x,y,z.
-project B imported A and at the same time libraries x,y,z were visible too
(could use classes x's for compile time).

in my point of view the automatic inclusion of transitive dependencies
should be avoided and directly used libraries should be included explicitly.
this makes maintenance in view of dependencies more feasible:
-so project B must include library x explicitly to use x's features, i.e.
transitive dependencies surely must be provided at runtime but should not be
visible for compile-time.

when we switched to maven2 we enforced this through marking all dependencies
as optional. this made dependencies of project A invisible for project B so
project B was enforced to include all directly used libraries to. having
read http://maven.apache.org/pom.html and explanation for optional flag
tells me that i misused optional:
"In the shortest terms, optional  lets other projects know that, when you
use this project, you do not require this dependency in order to work
correctly." 
what i think a bit confusing is the snippet (you do not require this
dependency in order to work correctly.), why should i then include this
dependency at all, if i do not need it...?

so, what is the correct maven2 way to make transitive dependencies invisible
by importing project?

-- 
View this message in context: http://www.nabble.com/maven2-way-to-hide-transitive-dependencies-tp14495957s177p14495957.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven2 way to hide transitive dependencies

Posted by Heinrich Nirschl <he...@gmail.com>.
On Dec 26, 2007 2:25 PM, aldana <al...@gmx.de> wrote:
> Heinrich Nirschl wrote:
> >
> > No, the optional library may be needed for compiling. It can still be
> > optional if it is never loaded at runtime for a certain use case.
> >
> but how should someone know if a certain use case is not executed on runtime
> (to me that sounds more like a hint to dead code...). do you know a real
> maven2 project where this optional is used and makes sense?

A good example is commons-logging:commons-logging:1.1.1. It has
optional dependencies on the logging frameworks it supports. When you
actually use it, you want just one framework and not all. Previous
versions did not have the dependencies declared as optional. As a
consequence, users had to write a lot of exclusions in the POM (or to
live with the unnecessary jars that were pulled in).

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven2 way to hide transitive dependencies

Posted by Wendy Smoak <ws...@gmail.com>.
On Dec 26, 2007 6:25 AM, aldana <al...@gmx.de> wrote:

> Heinrich Nirschl wrote:
> >
> > No, the optional library may be needed for compiling. It can still be
> > optional if it is never loaded at runtime for a certain use case.
> >
> but how should someone know if a certain use case is not executed on runtime
> (to me that sounds more like a hint to dead code...). do you know a real
> maven2 project where this optional is used and makes sense?

The Shale test framework has classes that depend on HtmlUnit and
Cargo.  Those dependencies need to be on the classpath to compile the
framework itself, but they are marked optional in order to avoid
imposing them on all users of the test framework.   Depending on the
type of testing you're doing, you declare the additional dependencies
you need.

http://svn.apache.org/repos/asf/shale/framework/trunk/shale-test/pom.xml

-- 
Wendy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven2 way to hide transitive dependencies

Posted by aldana <al...@gmx.de>.


Heinrich Nirschl wrote:
> 
> "mvn dependency:analyze" may also help to detect situations where
> transitive dependencies should better be declared as direct
> dependencies.
> 
great! eveyday to learn something new.


Heinrich Nirschl wrote:
> 
> No, the optional library may be needed for compiling. It can still be
> optional if it is never loaded at runtime for a certain use case.
> 
but how should someone know if a certain use case is not executed on runtime
(to me that sounds more like a hint to dead code...). do you know a real
maven2 project where this optional is used and makes sense?


-- 
View this message in context: http://www.nabble.com/maven2-way-to-hide-transitive-dependencies-tp14495957s177p14502190.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven2 way to hide transitive dependencies

Posted by Heinrich Nirschl <he...@gmail.com>.
On Dec 25, 2007 7:12 PM, aldana <al...@gmx.de> wrote:
>
> that makes sense... so it seems that these checks will only be possible on
> syntax level (check, if used types are from direct or transitive
> dependencies), maybe i will give this check a try with a syntax analyzer
> integrated in a continous integration build.
> of course this won't save me from dynamic level (reflection). well, let's
> see what can be done to at least reduce the direct access of transitive
> libraries for this really makes maintaining difficult (e.g. site-effects
> when removing library with loads of dependencies).
>

"mvn dependency:analyze" may also help to detect situations where
transitive dependencies should better be declared as direct
dependencies.

>
> so optional libraries only make sense if scope-marked as runtime...?
>

No, the optional library may be needed for compiling. It can still be
optional if it is never loaded at runtime for a certain use case.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven2 way to hide transitive dependencies

Posted by aldana <al...@gmx.de>.
that makes sense... so it seems that these checks will only be possible on
syntax level (check, if used types are from direct or transitive
dependencies), maybe i will give this check a try with a syntax analyzer
integrated in a continous integration build.
of course this won't save me from dynamic level (reflection). well, let's
see what can be done to at least reduce the direct access of transitive
libraries for this really makes maintaining difficult (e.g. site-effects
when removing library with loads of dependencies).


Heinrich Nirschl wrote:
> 
> Unfortunately, this does not work. There are situations where the
> transitive dependencies
> are needed even during compile time (e.g. B uses a class from A that
> inherits from something in x).
> 


so optional libraries only make sense if scope-marked as runtime...?

Heinrich Nirschl wrote:
> 
> The module with the optional dependency could check at runtime if it
> is available in the class path and only use it if it can be found.
> 

-- 
View this message in context: http://www.nabble.com/maven2-way-to-hide-transitive-dependencies-tp14495957s177p14496621.html
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven2 way to hide transitive dependencies

Posted by Heinrich Nirschl <he...@gmail.com>.
On Dec 25, 2007 5:06 PM, aldana <al...@gmx.de> wrote:
>
> in my point of view the automatic inclusion of transitive dependencies
> should be avoided and directly used libraries should be included explicitly.
> this makes maintenance in view of dependencies more feasible:
> -so project B must include library x explicitly to use x's features, i.e.
> transitive dependencies surely must be provided at runtime but should not be
> visible for compile-time.

Unfortunately, this does not work. There are situations where the
transitive dependencies
are needed even during compile time (e.g. B uses a class from A that
inherits from something in x).

>
> when we switched to maven2 we enforced this through marking all dependencies
> as optional. this made dependencies of project A invisible for project B so
> project B was enforced to include all directly used libraries to. having
> read http://maven.apache.org/pom.html and explanation for optional flag
> tells me that i misused optional:
> "In the shortest terms, optional  lets other projects know that, when you
> use this project, you do not require this dependency in order to work
> correctly."
> what i think a bit confusing is the snippet (you do not require this
> dependency in order to work correctly.), why should i then include this
> dependency at all, if i do not need it...?

The module with the optional dependency could check at runtime if it
is available in the class path and only use it if it can be found.

- Henry

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org