Skip to content
Jan Dudek edited this page Jun 20, 2013 · 46 revisions

Adding Jadler to Your Project

The easiest way to add Jadler to a Maven based project is putting the jadler-all dependency to the pom.xml file:

<dependencies>
    <dependency>
        <groupId>net.jadler</groupId>
        <artifactId>jadler-all</artifactId>
        <version>0.9.5</version>
        <scope>test</scope>
    </dependency>
</dependencies>

The jadler-all artifact automatically adds all Jadler components.

Fine Tuning the Jadler Inclusion

Instead of adding all Jadler components automatically to your project you can just specify the modules you really need. Jadler consists of following modules:

  • jadler-core - base Jadler module, mandatory for Jadler usage
  • jadler-jetty - Jetty based implementation of an http stub server. This dependency is necessary if the default Jetty based stub server is intended to be used.

To add both modules to a Maven based projects just put the following dependencies to the pom.xml file:

<dependencies>
    <dependency>
        <groupId>net.jadler</groupId>
        <artifactId>jadler-core</artifactId>
        <version>0.9.5</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>net.jadler</groupId>
        <artifactId>jadler-jetty</artifactId>
        <version>0.9.5</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Jadler & JUnit

It comes as no surprise that Jadler will be very often used in conjunction with JUnit. However there's a catch when using JUnit prior the 4.11 version. It has few Hamcrest classes embedded (inlined) coming from the old 1.1 version while Jadler requires the newest 1.3 version.

To include JUnit prior 4.11 to your Maven project use the junit-dep artifact instead of the more common junit:

<dependencies>
    <dependency>
        <groupId>net.jadler</groupId>
        <artifactId>jadler-all</artifactId>
        <version>0.9.5</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit-dep</artifactId>
        <version>4.10</version>
        <exclusions>
            <exclusion>
                <groupId>org.hamcrest</groupId>
                <artifactId>hamcrest-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

The exclusion ensures Maven doesn't resolve the hamcrest-core dependency in favor of the old 1.1 version. Instead of an exclusion one can use a dependency management section:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <version>1.3</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>net.jadler</groupId>
        <artifactId>jadler-all</artifactId>
        <version>0.9.5</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit-dep</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
</dependencies>

The dependency section explicitly enforces a specific version of a library. More on the topic can be found in What's up with the JUnit and Hamcrest Dependencies?.

Jadler & Mockito

Mockito is another library Jadler will be very often used along with.

The mockito-all artifact has few Hamcrest classes (in 1.1 version) embedded as well so it's necessary to add mockito-core instead. And since mockito-core depends on hamcrest-core version 1.1, it must be excluded in the exactly same way as already described before (either using an exclusion or a dependency-management section):