You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Henri Yandell <ba...@generationjava.com> on 2003/04/24 21:45:10 UTC

Test Dependencies

My Unit Tests want to use a jndi implementation and a jdbc implementation.
Do I have to declare these as dependencies?

Has the whole issue of runtime/compile-time/test-time dependencies been
solved in recent versions? I remember and early maven version coming with
a comment about how a difference between runtime and compile-time
dependencies was needed.

Hen


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


RE: Test Dependencies

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

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

  <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 real 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.

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



> -----Original Message-----
> From: Henri Yandell [mailto:bayard@generationjava.com]
> Sent: Thursday, April 24, 2003 3:45 PM
> To: Maven Users List
> Subject: Test Dependencies
>
>
>
> My Unit Tests want to use a jndi implementation and a jdbc implementation.
> Do I have to declare these as dependencies?
>
> Has the whole issue of runtime/compile-time/test-time dependencies been
> solved in recent versions? I remember and early maven version coming with
> a comment about how a difference between runtime and compile-time
> dependencies was needed.
>
> Hen


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