You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by ce...@lodh.com on 2006/08/15 15:32:26 UTC

Dependency scopes

Hello,

I would like to ask a question regarding dependency scopes in
Maven2. After reading the article "Introduction to the Dependency
Mechanism" [1], I've got several questions that may have been answered
previously. I apologize in advance if that is the case.

The said article mentions the notion of "runtime classpath." While I
can see what compile and test classpaths mean, I fail to understand
what a runtime classpath is, in particular how it differs from the
test classpath.

Moreover, the article defines  "provided scope" as follows:

 provided - this is much like compile, but indicates you expect theJDK
    or a container to provide it.  It is only available on the compilation
   classpath, and is not transitive.

However, in a small project I've created to test dependency scopes, it
seems that a dependency declared with the "provided" scope is
available when compiling the source, compiling the test cases as well
as when running them (the test cases). Thus, it looks like the
provided scope is the same as the compile scope, except that the
provided scope is not transitive.

The difference between the runtime and test scopes is also not very
clear to me.

The small table which illustrates the effects of scopes on
transitivity is not easy to grok. In particular, the explanation
(quoted below) preceding the table does not define the direction of
any of the dependencies.

<quote>
Each of the scopes affects transitive dependencies in different ways,
as is demonstrated in the table below. If a dependency is set to the
scope in the left column, dependencies with the scope across the top
row will result in a dependency in the main project with the scope
listed at the intersection. If no scope is listed, it means the
dependency will be omitted.
</quote>

Your enlightenment would be greatly appreciated,

[1] 
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html


************************ DISCLAIMER ************************
This message is intended only for use by the person
to whom it is addressed. It may contain information
that is privileged and confidential. Its content does
not constitute a formal commitment by Lombard
Odier Darier Hentsch Group and any of its affiliates.
If you are not the intended recipient of this message,
kindly notify the sender immediately and destroy this
message. Thank You.
*****************************************************************


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


Re: Dependency scopes

Posted by Nick Veys <ps...@gmail.com>.
On 8/17/06, ceki@lodh.com <ce...@lodh.com> wrote:
> Nick,
>
> I very much appreciate your response. I wish the article of reference
> on subject, namely, "Introduction to the Dependency Mechanism" was
> somewhat more precise. Perhaps the maintainers of the document could
> have another look at it. Is filing a bug report appropriate?

As far as I know that's how they operate, yes.

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


Re: Re: Re: Dependency scopes

Posted by ce...@lodh.com.
Thanks!


















"Martijn Dashorst" <ma...@gmail.com>
 
 
30.08.2006 16:17 
Please respond to
"Maven Users List" <us...@maven.apache.org>



To
"Maven Users List" <us...@maven.apache.org>
cc

Subject
Re: Re: Re: Dependency scopes



 Reviewed by         Category 


Yes, but "runtime classpath" != "runtime scope"

runtime classpath == union(compile, runtime scope)

Martijn

On 8/30/06, ceki@lodh.com <ce...@lodh.com> wrote:
> So, this means that war and ear plug-ins reference the runtime classpath
> instead of say compile or test. Correct?
>
> "Martijn Dashorst" <ma...@gmail.com> wrote on 30.08.2006
> 15:37:56:
>
> > No, but maven is also used to create war, ear and other distribution
> > packages. These packages need those actual runtime dependencies inside
> > them.
> >
> > So for testing I need junit, but not at runtime -> test scope
> > For testing I may not have a need for oracle-jdbc (using hsqldb for
> > unittests), but at runtime I will (if deploying on an oracle database)
> > -> runtime scope.
> >
> > For testing I need the interfaces for the servlet api, but those
> > interfaces are available at runtiime in the tomcat server for my web
> > application. So the servlet api JAR (javax.servlet-2.3.jar) is needed
> > for compile *and* test, but doesn't need to go into the WAR archive ->
> > provided scope.
> >
> > hth.
> >
> > Martijn
>
>
> ************************ DISCLAIMER ************************
> This message is intended only for use by the person
> to whom it is addressed. It may contain information
> that is privileged and confidential. Its content does
> not constitute a formal commitment by Lombard
> Odier Darier Hentsch Group and any of its affiliates.
> If you are not the intended recipient of this message,
> kindly notify the sender immediately and destroy this
> message. Thank You.
> *****************************************************************
>
>


-- 
Download Wicket 1.2.2 now! New Ajax components: Tree, TreeTable and 
ModalWindow
-- http://wicketframework.org

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




************************ DISCLAIMER ************************
This message is intended only for use by the person
to whom it is addressed. It may contain information
that is privileged and confidential. Its content does
not constitute a formal commitment by Lombard
Odier Darier Hentsch Group and any of its affiliates.
If you are not the intended recipient of this message,
kindly notify the sender immediately and destroy this
message. Thank You.
*****************************************************************

Re: Re: Re: Dependency scopes

Posted by Martijn Dashorst <ma...@gmail.com>.
Yes, but "runtime classpath" != "runtime scope"

runtime classpath == union(compile, runtime scope)

Martijn

On 8/30/06, ceki@lodh.com <ce...@lodh.com> wrote:
> So, this means that war and ear plug-ins reference the runtime classpath
> instead of say compile or test. Correct?
>
> "Martijn Dashorst" <ma...@gmail.com> wrote on 30.08.2006
> 15:37:56:
>
> > No, but maven is also used to create war, ear and other distribution
> > packages. These packages need those actual runtime dependencies inside
> > them.
> >
> > So for testing I need junit, but not at runtime -> test scope
> > For testing I may not have a need for oracle-jdbc (using hsqldb for
> > unittests), but at runtime I will (if deploying on an oracle database)
> > -> runtime scope.
> >
> > For testing I need the interfaces for the servlet api, but those
> > interfaces are available at runtiime in the tomcat server for my web
> > application. So the servlet api JAR (javax.servlet-2.3.jar) is needed
> > for compile *and* test, but doesn't need to go into the WAR archive ->
> > provided scope.
> >
> > hth.
> >
> > Martijn
>
>
> ************************ DISCLAIMER ************************
> This message is intended only for use by the person
> to whom it is addressed. It may contain information
> that is privileged and confidential. Its content does
> not constitute a formal commitment by Lombard
> Odier Darier Hentsch Group and any of its affiliates.
> If you are not the intended recipient of this message,
> kindly notify the sender immediately and destroy this
> message. Thank You.
> *****************************************************************
>
>


-- 
Download Wicket 1.2.2 now! New Ajax components: Tree, TreeTable and ModalWindow
-- http://wicketframework.org

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


Re: Re: Dependency scopes

Posted by ce...@lodh.com.
So, this means that war and ear plug-ins reference the runtime classpath 
instead of say compile or test. Correct?

"Martijn Dashorst" <ma...@gmail.com> wrote on 30.08.2006 
15:37:56:

> No, but maven is also used to create war, ear and other distribution
> packages. These packages need those actual runtime dependencies inside
> them.
> 
> So for testing I need junit, but not at runtime -> test scope
> For testing I may not have a need for oracle-jdbc (using hsqldb for
> unittests), but at runtime I will (if deploying on an oracle database)
> -> runtime scope.
> 
> For testing I need the interfaces for the servlet api, but those
> interfaces are available at runtiime in the tomcat server for my web
> application. So the servlet api JAR (javax.servlet-2.3.jar) is needed
> for compile *and* test, but doesn't need to go into the WAR archive ->
> provided scope.
> 
> hth.
> 
> Martijn


************************ DISCLAIMER ************************
This message is intended only for use by the person
to whom it is addressed. It may contain information
that is privileged and confidential. Its content does
not constitute a formal commitment by Lombard
Odier Darier Hentsch Group and any of its affiliates.
If you are not the intended recipient of this message,
kindly notify the sender immediately and destroy this
message. Thank You.
*****************************************************************

Re: Re: Dependency scopes

Posted by Martijn Dashorst <ma...@gmail.com>.
No, but maven is also used to create war, ear and other distribution
packages. These packages need those actual runtime dependencies inside
them.

So for testing I need junit, but not at runtime -> test scope
For testing I may not have a need for oracle-jdbc (using hsqldb for
unittests), but at runtime I will (if deploying on an oracle database)
-> runtime scope.

For testing I need the interfaces for the servlet api, but those
interfaces are available at runtiime in the tomcat server for my web
application. So the servlet api JAR (javax.servlet-2.3.jar) is needed
for compile *and* test, but doesn't need to go into the WAR archive ->
provided scope.

hth.

Martijn

On 8/30/06, ceki@lodh.com <ce...@lodh.com> wrote:
> > On 8/15/06, ceki@lodh.com <ce...@lodh.com> wrote:
> >
> > > The difference between the runtime and test scopes is also not very
> > > clear to me.
>
> "Nick Veys" <ps...@gmail.com> wrote on 17.08.2006 06:16:40:
>
> > This was already answered, but the test dependencies aren't needed for
> > "normal" runtime, so they are left out.  It allows you to pull in a
> > test harness, or mock libraries during your tests but leave that out
> > for "real" execution or packaging.
>
> While I understand that certain libs may be required at compile time
> but not compile time, I don't see what "normal" runtime means in terms
> of Maven. Maven is a build system, it does not execute your
> applications, so how can it have a runtime classpath? There is no
> such thing as runtime Maven or is there?
>
>
> ************************ DISCLAIMER ************************
> This message is intended only for use by the person
> to whom it is addressed. It may contain information
> that is privileged and confidential. Its content does
> not constitute a formal commitment by Lombard
> Odier Darier Hentsch Group and any of its affiliates.
> If you are not the intended recipient of this message,
> kindly notify the sender immediately and destroy this
> message. Thank You.
> *****************************************************************
>
>


-- 
Download Wicket 1.2.2 now! New Ajax components: Tree, TreeTable and ModalWindow
-- http://wicketframework.org

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


Re: Dependency scopes

Posted by ce...@lodh.com.
> On 8/15/06, ceki@lodh.com <ce...@lodh.com> wrote:
> 
> > The difference between the runtime and test scopes is also not very
> > clear to me.

"Nick Veys" <ps...@gmail.com> wrote on 17.08.2006 06:16:40:

> This was already answered, but the test dependencies aren't needed for
> "normal" runtime, so they are left out.  It allows you to pull in a
> test harness, or mock libraries during your tests but leave that out
> for "real" execution or packaging.

While I understand that certain libs may be required at compile time
but not compile time, I don't see what "normal" runtime means in terms
of Maven. Maven is a build system, it does not execute your
applications, so how can it have a runtime classpath? There is no
such thing as runtime Maven or is there? 


************************ DISCLAIMER ************************
This message is intended only for use by the person
to whom it is addressed. It may contain information
that is privileged and confidential. Its content does
not constitute a formal commitment by Lombard
Odier Darier Hentsch Group and any of its affiliates.
If you are not the intended recipient of this message,
kindly notify the sender immediately and destroy this
message. Thank You.
*****************************************************************

Re: Dependency scopes

Posted by franz see <fr...@gmail.com>.
> Nick,
> 
> I very much appreciate your response. I wish the article of reference
> on subject, namely, "Introduction to the Dependency Mechanism" was
> somewhat more precise. Perhaps the maintainers of the document could
> have another look at it. Is filing a bug report appropriate?

Good day to you, ceki-3,

You can file one under MNG - Documentation: Introductions ([1]) ^_^

[1]
http://jira.codehaus.org/secure/IssueNavigator.jspa?reset=true&mode=hide&pid=10500&sorter/order=DESC&sorter/field=priority&resolution=-1&component=11872

Cheers, 
Franz
-- 
View this message in context: http://www.nabble.com/Dependency-scopes-tf2109159.html#a5860766
Sent from the Maven - Users forum at Nabble.com.


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


Re: Dependency scopes

Posted by ce...@lodh.com.
Nick,

I very much appreciate your response. I wish the article of reference
on subject, namely, "Introduction to the Dependency Mechanism" was
somewhat more precise. Perhaps the maintainers of the document could
have another look at it. Is filing a bug report appropriate?


"Nick Veys" <ps...@gmail.com> wrote on 17.08.2006 06:16:40:

> On 8/15/06, ceki@lodh.com <ce...@lodh.com> wrote:
> > The said article mentions the notion of "runtime classpath." While I
> > can see what compile and test classpaths mean, I fail to understand
> > what a runtime classpath is, in particular how it differs from the
> > test classpath.
> 
> Think of Runtime as somewhat of an optimization for the build process.
>  The jar itself is not needed to compile the code as it has no direct
> dependency on it, though the code itself still needs this jar to
> execute, as such it will travel along transitively in case it is
> needed down the line, and will also be included in the test scope as
> it may be called upon since the code has a runtime dependency on it.
> 
> > Moreover, the article defines  "provided scope" as follows:
> >
> >  provided - this is much like compile, but indicates you expect theJDK
> >     or a container to provide it.  It is only available on the 
compilation
> >    classpath, and is not transitive.
> >
> > However, in a small project I've created to test dependency scopes, it
> > seems that a dependency declared with the "provided" scope is
> > available when compiling the source, compiling the test cases as well
> > as when running them (the test cases). Thus, it looks like the
> > provided scope is the same as the compile scope, except that the
> > provided scope is not transitive.
> 
> The documentation may be slightly wrong, as you experienced the
> provided scope jars are available to tests (at least in my
> experience), though I believe only that local project tests, as you
> have no transitivity (I may be wrong here, corrections?).  Provided is
> very much like compile w/o transitivity.  It is assumed that your
> container or system will provide this jar when needed.
> 
> > The difference between the runtime and test scopes is also not very
> > clear to me.
> 
> This was already answered, but the test dependencies aren't needed for
> "normal" runtime, so they are left out.  It allows you to pull in a
> test harness, or mock libraries during your tests but leave that out
> for "real" execution or packaging.
> 
> > The small table which illustrates the effects of scopes on
> > transitivity is not easy to grok. In particular, the explanation
> > (quoted below) preceding the table does not define the direction of
> > any of the dependencies.
> 
> I'm guessing it's trying to tell you the precidence of dependencies
> when the same dependency is referenced in multiple scopes in one
> project, but you're right, the preceeding paragraph is not exactly
> clear in what it is talking about.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 


************************ DISCLAIMER ************************
This message is intended only for use by the person
to whom it is addressed. It may contain information
that is privileged and confidential. Its content does
not constitute a formal commitment by Lombard
Odier Darier Hentsch Group and any of its affiliates.
If you are not the intended recipient of this message,
kindly notify the sender immediately and destroy this
message. Thank You.
*****************************************************************

Re: Dependency scopes

Posted by Nick Veys <ps...@gmail.com>.
On 8/15/06, ceki@lodh.com <ce...@lodh.com> wrote:
> The said article mentions the notion of "runtime classpath." While I
> can see what compile and test classpaths mean, I fail to understand
> what a runtime classpath is, in particular how it differs from the
> test classpath.

Think of Runtime as somewhat of an optimization for the build process.
 The jar itself is not needed to compile the code as it has no direct
dependency on it, though the code itself still needs this jar to
execute, as such it will travel along transitively in case it is
needed down the line, and will also be included in the test scope as
it may be called upon since the code has a runtime dependency on it.

> Moreover, the article defines  "provided scope" as follows:
>
>  provided - this is much like compile, but indicates you expect theJDK
>     or a container to provide it.  It is only available on the compilation
>    classpath, and is not transitive.
>
> However, in a small project I've created to test dependency scopes, it
> seems that a dependency declared with the "provided" scope is
> available when compiling the source, compiling the test cases as well
> as when running them (the test cases). Thus, it looks like the
> provided scope is the same as the compile scope, except that the
> provided scope is not transitive.

The documentation may be slightly wrong, as you experienced the
provided scope jars are available to tests (at least in my
experience), though I believe only that local project tests, as you
have no transitivity (I may be wrong here, corrections?).  Provided is
very much like compile w/o transitivity.  It is assumed that your
container or system will provide this jar when needed.

> The difference between the runtime and test scopes is also not very
> clear to me.

This was already answered, but the test dependencies aren't needed for
"normal" runtime, so they are left out.  It allows you to pull in a
test harness, or mock libraries during your tests but leave that out
for "real" execution or packaging.

> The small table which illustrates the effects of scopes on
> transitivity is not easy to grok. In particular, the explanation
> (quoted below) preceding the table does not define the direction of
> any of the dependencies.

I'm guessing it's trying to tell you the precidence of dependencies
when the same dependency is referenced in multiple scopes in one
project, but you're right, the preceeding paragraph is not exactly
clear in what it is talking about.

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


Re: Dependency scopes

Posted by ce...@lodh.com.
Mike, thank you for taking the time to respond. My question had
several parts and your response relates to the difference between
runtime scope and the test scope. I wonder if someone would care to
respond to the remaining parts.

Mike Perham <mp...@us.ibm.com> wrote on 15.08.2006 18:04:17:

> 
> Runtime - contains things that you don't need at compile but you do need
> for your app to actually run.  You might compile against JMS but require
> ActiveMQ at runtime (i.e. a JMS engine).
> Test - contains test specific classes.  Junit, mocks, a lightweight
> database like HSQLDB, etc.
> 
> ceki@lodh.com wrote on 08/15/2006 08:32:26 AM:
> 
> > Hello,
> >
> > I would like to ask a question regarding dependency scopes in
> > Maven2. After reading the article "Introduction to the Dependency
> > Mechanism" [1], I've got several questions that may have been answered
> > previously. I apologize in advance if that is the case.
> >
> > The said article mentions the notion of "runtime classpath." While I
> > can see what compile and test classpaths mean, I fail to understand
> > what a runtime classpath is, in particular how it differs from the
> > test classpath.
> >
> > Moreover, the article defines  "provided scope" as follows:
> >
> >  provided - this is much like compile, but indicates you expect theJDK
> >     or a container to provide it.  It is only available on the
> compilation
> >    classpath, and is not transitive.
> >
> > However, in a small project I've created to test dependency scopes, it
> > seems that a dependency declared with the "provided" scope is
> > available when compiling the source, compiling the test cases as well
> > as when running them (the test cases). Thus, it looks like the
> > provided scope is the same as the compile scope, except that the
> > provided scope is not transitive.
> >
> > The difference between the runtime and test scopes is also not very
> > clear to me.
> >
> > The small table which illustrates the effects of scopes on
> > transitivity is not easy to grok. In particular, the explanation
> > (quoted below) preceding the table does not define the direction of
> > any of the dependencies.
> >
> > <quote>
> > Each of the scopes affects transitive dependencies in different ways,
> > as is demonstrated in the table below. If a dependency is set to the
> > scope in the left column, dependencies with the scope across the top
> > row will result in a dependency in the main project with the scope
> > listed at the intersection. If no scope is listed, it means the
> > dependency will be omitted.
> > </quote>
> >
> > Your enlightenment would be greatly appreciated,
> >
> > [1]
> > http://maven.apache.org/guides/introduction/introduction-to-
> > dependency-mechanism.html


************************ DISCLAIMER ************************
This message is intended only for use by the person
to whom it is addressed. It may contain information
that is privileged and confidential. Its content does
not constitute a formal commitment by Lombard
Odier Darier Hentsch Group and any of its affiliates.
If you are not the intended recipient of this message,
kindly notify the sender immediately and destroy this
message. Thank You.
*****************************************************************


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


Re: Dependency scopes

Posted by Mike Perham <mp...@us.ibm.com>.



Runtime - contains things that you don't need at compile but you do need
for your app to actually run.  You might compile against JMS but require
ActiveMQ at runtime (i.e. a JMS engine).
Test - contains test specific classes.  Junit, mocks, a lightweight
database like HSQLDB, etc.

ceki@lodh.com wrote on 08/15/2006 08:32:26 AM:

> Hello,
>
> I would like to ask a question regarding dependency scopes in
> Maven2. After reading the article "Introduction to the Dependency
> Mechanism" [1], I've got several questions that may have been answered
> previously. I apologize in advance if that is the case.
>
> The said article mentions the notion of "runtime classpath." While I
> can see what compile and test classpaths mean, I fail to understand
> what a runtime classpath is, in particular how it differs from the
> test classpath.
>
> Moreover, the article defines  "provided scope" as follows:
>
>  provided - this is much like compile, but indicates you expect theJDK
>     or a container to provide it.  It is only available on the
compilation
>    classpath, and is not transitive.
>
> However, in a small project I've created to test dependency scopes, it
> seems that a dependency declared with the "provided" scope is
> available when compiling the source, compiling the test cases as well
> as when running them (the test cases). Thus, it looks like the
> provided scope is the same as the compile scope, except that the
> provided scope is not transitive.
>
> The difference between the runtime and test scopes is also not very
> clear to me.
>
> The small table which illustrates the effects of scopes on
> transitivity is not easy to grok. In particular, the explanation
> (quoted below) preceding the table does not define the direction of
> any of the dependencies.
>
> <quote>
> Each of the scopes affects transitive dependencies in different ways,
> as is demonstrated in the table below. If a dependency is set to the
> scope in the left column, dependencies with the scope across the top
> row will result in a dependency in the main project with the scope
> listed at the intersection. If no scope is listed, it means the
> dependency will be omitted.
> </quote>
>
> Your enlightenment would be greatly appreciated,
>
> [1]
> http://maven.apache.org/guides/introduction/introduction-to-
> dependency-mechanism.html
>
>
> ************************ DISCLAIMER ************************
> This message is intended only for use by the person
> to whom it is addressed. It may contain information
> that is privileged and confidential. Its content does
> not constitute a formal commitment by Lombard
> Odier Darier Hentsch Group and any of its affiliates.
> If you are not the intended recipient of this message,
> kindly notify the sender immediately and destroy this
> message. Thank You.
> *****************************************************************
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>