tags:

views:

20

answers:

3

how to exclude a dependency from war but using it till testing or development

+1  A: 

There is an option to specify scope with in the dependency tag. You can specify scope as test and it won't be included into your war but will only be used for tests.

Ankit
A: 

You do it with <scope>provided</scope> tag.

    <dependency>
        <groupId>org.livetribe</groupId>
        <artifactId>livetribe-jsr223</artifactId>
        <version>2.0.6</version>
        <scope>provided</scope>
    </dependency>
amra
A: 

As the others suggested, scope=provided or scope=test is the way to go.

  1. <scope>provided</scope> implies that the library will be present in the target system and doesn't need to be deployed. (Or in some cases like log4j must not be deployed, because otherwise classloader issues will result)
  2. <scope>test</scope> suggests that the dependency is only needed for test code (and hence will not be needed or provided on the target system)

Here is the relevant documentation:

Introduction to the Dependency Mechanism

On a related note: A different use case is that where you use different databases on different servers. You can use profiles to deploy the correct drivers:

<profiles>
    <profile>
        <id>testserver</id>
        <dependencies>
            <dependency>
            ... (database driver a)
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>productionserver</id>
        <dependencies>
            <dependency>
            ... (database driver b)
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>localdevelopment</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <dependencies>
            <dependency>
            ... (database driver c)
            </dependency>
        </dependencies>
    </profile>
</profiles>

That way, if you just call mvn install, driver c will be deployed, whereas mvn install -Ptestserver and mvn install -Pproductionserver will include drivers a or b, respectively.

seanizer