lucas
lucas

Reputation: 1

Spring Rest Docs error calling docs / index.html

When I call localhost:8080/index.html I get a 404 error. I'm using gradle and kotlin. Here is my build.gradle.kts:

plugins {
    id("org.springframework.boot") version "2.2.3.RELEASE"
    id("io.spring.dependency-management") version "1.0.8.RELEASE"
    id("org.asciidoctor.convert") version "1.5.9.2"
    kotlin("jvm") version "1.3.61"
    kotlin("plugin.spring") version "1.3.61"

}

version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

val snippetsDir = file("build/generated-snippets")

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    asciidoctor("org.springframework.restdocs:spring-restdocs-asciidoctor")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
    testImplementation("org.springframework.restdocs:spring-restdocs-webtestclient")


}

tasks{

    withType<Test> {
        useJUnitPlatform()
    }

    withType<KotlinCompile> {
        kotlinOptions {
            freeCompilerArgs = listOf("-Xjsr305=strict")
            jvmTarget = "1.8"
        }
    }

    test {
        outputs.dir(snippetsDir)
    }

    asciidoctor {
        inputs.dir(snippetsDir)
        dependsOn("test")
    }

    asciidoctor{
        outputDir = file("build/docs")
    }



    bootJar {
        dependsOn("asciidoctor")
        from ("${asciidoctor.get().outputDir}/html5") {
            into("static/docs")
        }

    }
} 

Any idea what I might be doing wrong?

Does Spring Rest Docs support build.gradle.kts? From what I've been looking at in the documentation, I didn't find anything talking about it.

Upvotes: 0

Views: 927

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116281

Spring Boot will automatically serve static resources on /. It finds those resources by looking in your jar's static/ folder (among other places). You've packaged the documentation in static/docs which means that it will be available from /docs/ but you are making a request to /index.html. A request to /docs/index.html should respond with the documentation.

Upvotes: 0

Related Questions