You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Scott Stirling <sc...@rcn.com> on 2003/06/05 02:06:53 UTC

Refining dependencies for test and non-test

Hi,

Wondering how and whether it's possible to refine a project's dependency set
so that unit/integration test dependencies are separate from non-test
dependencies.

For example, if I have jars that a JUnit extension library needs at runtime,
but which I don't want to have in the classpath at build time for my classes
(or perhaps my classes require a different version of a jar), how do I
separate them at compile time and/or runtime?

Thank you,

Scott Stirling
Framingham, MA



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


RE: Refining dependencies for test and non-test

Posted by David Zeleznik <dz...@ilog.com>.
Hi Paulo,

> Michal seems to be currently working in some tags for
> the dependecies, where you can say what <kind> of dependecy
> you have.
>
> This way you can say to maven that servlet.jar is a compile
> dependecy, and not a runtime one, so it will not be copied
> to a war, for example. And you can define your own <kind>s.
>
> This way you will be able to handle your tests classpath.

Thanks for the info, that sounds like it would help us out greatly. We are
still using beta8 because we ran into so many bugs with beta9. Do you know
if this new capability is in the current CVS head? If so, where would I look
for a a good example of its usage?

Thanks,

--------------------------------------
David Zeleznik
ILOG - Changing the rules of business
mailto:dzeleznik@ilog.com
http://www.ilog.com
--------------------------------------


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


RE: Refining dependencies for test and non-test

Posted by Paulo Silveira <pa...@paulo.com.br>.
Hello

> I hope this gives you some ideas. Right now, mucking with 
> Maven's dependency classpath is quite messy. It would be  
> nice if there was a set of easy-to-use tags so that a plugin 
> could do and undo changes to the classpath, like a stack. 
> However, this solution works fine for us now.

Michal seems to be currently working in some tags for 
the dependecies, where you can say what <kind> of dependecy 
you have.

This way you can say to maven that servlet.jar is a compile
dependecy, and not a runtime one, so it will not be copied
to a war, for example. And you can define your own <kind>s.

This way you will be able to handle your tests classpath. 

> 
> Regards,
> 
> --------------------------------------
> David Zeleznik
> ILOG - Changing the rules of business
> mailto:dzeleznik@ilog.com
> http://www.ilog.com
> --------------------------------------
> 
> 
> > -----Original Message-----
> > From: Scott Stirling [mailto:scottstirling@rcn.com]
> > Sent: Wednesday, June 04, 2003 8:07 PM
> > To: 'Maven Users List'
> > Subject: Refining dependencies for test and non-test
> >
> >
> > Hi,
> >
> > Wondering how and whether it's possible to refine a project's 
> > dependency set so that unit/integration test dependencies 
> are separate 
> > from non-test dependencies.
> >
> > For example, if I have jars that a JUnit extension library needs at 
> > runtime, but which I don't want to have in the classpath at 
> build time 
> > for my classes
> > (or perhaps my classes require a different version of a 
> jar), how do I
> > separate them at compile time and/or runtime?
> >
> > Thank you,
> >
> > Scott Stirling
> > Framingham, MA
> >
> >
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 



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


RE: Refining dependencies for test and non-test

Posted by David Zeleznik <dz...@ilog.com>.
Hi,

AFAIK, the issue of separate paths for building and testing has not been
addressed in Maven. We have a situation that sounds similar to yours. We
have several test frameworks and we use 0..n of these frameworks in any
given project. However, we do not want these test frameworks to be put in
the compile class path for the regular project source code- we only want the
test frameworks in the compile and run path for the unit tests. Each
test-framework is its own project and is deployed to our central repository.
What we have done is to standardize on an optional project-tests.xml
descriptor that specifies the unit test dependencies for a project. We then
have pre and post test goals that read the dependencies from this optional
pom and add them to the test classpath by calling these 2 goals:

  <goal name="addTestDependencies" >
    <available
      property="testPomPresent"
      file="${basedir}/project-tests.xml" />
    <j:if test="${testPomPresent}">
      <j:set var="testPathX"
value="${pom.getAntProject().getReference('test.path')}X"/>
      <j:if test="${testPathX == 'X'}" >
        <!-- Read the POM that describes test-specific dependencies and then
             verify those dependencies from the repo. -->
        <m:pom projectDescriptor="${basedir}/project-tests.xml"
var="testPom"/>
        <j:set var="dummyVar" value="${testPom.verifyDependencies()}" />
        <path id="test.path" path="${testPom.getDependencyClasspath()}" />
      </j:if>
      <!-- Save Maven's current class path as a string. Because it is a true
           Ant path object, we cannot simply declare a new variable that
           references the same object we are about to change. Also, we
cannot
           simply use the project's dependencyClasspath attribute because
other
           goals, such as clover, also make modifications to Maven's
dependency
           class path that we must preserve. -->
      <j:set
        var="savedPath"

value="${pom.getAntProject().getReference('maven.dependency.classpath').toSt
ring()}" />
      <!-- Add test-specific dependencies to the project's Ant-style
classpath
           structure. Note that this only modifies the Ant path object and
does
           not change the project's dependencyClasspath attribute. -->
      <m:addPath id="maven.dependency.classpath" refid="test.path" />
    </j:if>
  </goal>

  <goal name="removeTestDependencies" >
    <j:if test="${testPomPresent == 'true'}" >
      <!-- Restore Maven's classpath by redefining it. -->
      <path id="maven.dependency.classpath">
        <pathelement path="${savedPath}" />
      </path>
    </j:if>
  </goal>

I hope this gives you some ideas. Right now, mucking with Maven's dependency
classpath is quite messy. It would be  nice if there was a set of
easy-to-use tags so that a plugin could do and undo changes to the
classpath, like a stack. However, this solution works fine for us now.

Regards,

--------------------------------------
David Zeleznik
ILOG - Changing the rules of business
mailto:dzeleznik@ilog.com
http://www.ilog.com
--------------------------------------


> -----Original Message-----
> From: Scott Stirling [mailto:scottstirling@rcn.com]
> Sent: Wednesday, June 04, 2003 8:07 PM
> To: 'Maven Users List'
> Subject: Refining dependencies for test and non-test
>
>
> Hi,
>
> Wondering how and whether it's possible to refine a project's
> dependency set
> so that unit/integration test dependencies are separate from non-test
> dependencies.
>
> For example, if I have jars that a JUnit extension library needs
> at runtime,
> but which I don't want to have in the classpath at build time for
> my classes
> (or perhaps my classes require a different version of a jar), how do I
> separate them at compile time and/or runtime?
>
> Thank you,
>
> Scott Stirling
> Framingham, MA
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>


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