spring-projects / spring-restdocs

Test-driven documentation for RESTful services
https://spring.io/projects/spring-restdocs
Apache License 2.0
1.16k stars 736 forks source link

JUnitRestDocumentation not found. #203

Closed geoHeil closed 8 years ago

geoHeil commented 8 years ago

Trying out the latest M1 release (https://github.com/spring-projects/spring-restdocs/blob/v1.1.0.M1/samples/rest-notes-spring-hateoas/src/test/java/com/example/notes/GettingStartedDocumentation.java) I stumbled upon a problem:

import org.springframework.restdocs.JUnitRestDocumentation; I cannot resolve this class. Do you have any hints what is wrong with my dependencies?


dependencies {
    compile 'org.springframework.boot:spring-boot-starter-actuator'
    compile 'org.springframework.boot:spring-boot-devtools'
    compile 'org.springframework.boot:spring-boot-starter-hateoas'
    compile 'org.springframework.boot:spring-boot-starter-logging'
    compile 'org.yaml:snakeyaml:1.16'
    compile 'org.springframework.data:spring-data-rest-hal-browser'

    testCompile 'org.springframework.boot:spring-boot-starter-test'
    testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:1.1.0.M1'
}

    ext {
        dependencyManagementPluginVersion = '0.5.5.RELEASE'
        springBootVersion = '1.3.2.RELEASE'
    }

    dependencyManagement {
        imports {
            mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
        }
    }
wilkinsona commented 8 years ago

The dependency management is overriding the version of spring-restdocs-core back to 1.0.x. Easiest thing to do is to override the version property that's in the spring-boot-dependencies bom:

ext['spring-restdocs.version']='1.1.0.M1'

You can then remove the version from your dependency:

testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc'
geoHeil commented 8 years ago

I added your suggestion like:

dependencyManagement {

        imports {
        ext['spring-restdocs.version'] = '1.1.0.M1'
            mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
        }
    }

and the correct version seems to be loaded according to:

\--- org.springframework.restdocs:spring-restdocs-mockmvc: -> 1.1.0.M1
     +--- org.springframework:spring-test:4.1.8.RELEASE -> 4.2.4.RELEASE (*)
     \--- org.springframework.restdocs:spring-restdocs-core:1.1.0.M1
          +--- javax.servlet:javax.servlet-api:3.1.0
          +--- org.springframework:spring-webmvc:4.1.8.RELEASE -> 4.2.4.RELEASE (*)
          \--- com.fasterxml.jackson.core:jackson-databind:2.4.6.1 -> 2.6.5 (*)

However, still the class is not found.

#edit Finally after deleting the caches and deleting recreating the project using gradle idea helped to solve the problem

wilkinsona commented 8 years ago

Glad to hear that you figured it out. Thanks for following up.