4

I'm trying to spin up a mock HTTP server for my testing, but I cannot get Wiremock to work.

On the mvnrepository.com website, it is suggested as such:

<!-- https://mvnrepository.com/artifact/com.github.tomakehurst/wiremock -->
<dependency>
    <groupId>com.github.tomakehurst</groupId>
    <artifactId>wiremock</artifactId>
    <version>2.9.0</version>
    <type>pom</type>
    <scope>test</scope>
</dependency>

This however, does not make it available to my test class when trying to import it as such:

import static com.github.tomakehurst.wiremock.client.WireMock.*;

If I remove the <type>pom</type> tag, I can import it but it then fails at runtime because it does not pull in all of the transitive dependencies it needs (such as the Apache Httpclient).

I am not really sure what <type>pom</type> does, as it's not really clear from other explanations, so I don't know how to get past this.

Full Maven config:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>-----</groupId>
    <artifactId>---------</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>-----------</name>
    <description>----------</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.rabbitmq</groupId>
            <artifactId>amqp-client</artifactId>
            <version>4.0.2</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.10.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>22.0</version>
        </dependency>

        <!-- Test dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock</artifactId>
            <version>2.9.0</version>
            <scope>test</scope>
            <type>pom</type>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <id>central</id>
            <name>bintray</name>
            <url>http://jcenter.bintray.com</url>
        </repository>
    </repositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
cgf
  • 3,369
  • 7
  • 45
  • 65
  • Have you tried `import`? https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope – SiKing Oct 18 '17 at 21:22
  • @SiKing I have now, no change. – cgf Oct 18 '17 at 21:25
  • After looking at the pom https://search.maven.org/remotecontent?filepath=com/github/tomakehurst/wiremock/2.9.0/wiremock-2.9.0.pom there is nothing special about it. It should definitely be `jar` (the default). What is the exact error you see? – SiKing Oct 18 '17 at 21:31
  • I just tried it, I get no problems. There must be something more to your setup! – SiKing Oct 18 '17 at 21:34
  • @SiKing I have tried commenting certain parts of the pom.xml file, but to no avail. There must be something else, but I don't know what it might be. I've pasted my full pom.xml file if you want to take a look. Thanks for the help! – cgf Oct 18 '17 at 21:45
  • Start with `mvn validate` and fix all errors and warnings. If you need more hints use `-X`. Then repeat with `mvn compile` and eventually `mvn test-compile`. If you do not know how to get past a specific error, post the text of that error. – SiKing Oct 18 '17 at 21:52
  • What exactly is your intention with the `` block? What exactly is your intention with the `` block? – SiKing Oct 18 '17 at 21:54
  • The `` block is just standard Spring Boot stuff - https://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-first-application.html. If you have any suggestions, I'm more than happy to remove it. – cgf Oct 18 '17 at 21:58
  • I've done `mvn validate`, `mvn compile` and `mvn test-comple`. It does get stuck in the test one with: `package com.github.tomakehurst.wiremock.junit does not exist` and `package com.github.tomakehurst.wiremock.client does not exist`. – cgf Oct 18 '17 at 21:59
  • Still cannot reproduce. `mvn dependecy:tree` will tell you who is trying to pull it in. – SiKing Oct 18 '17 at 22:11

1 Answers1

5

Try removing <type>pom</type> from the dependency.

Thomas Bratt
  • 48,038
  • 36
  • 121
  • 139