I use Spring Rest Docs and JIB
When i do ./gradlew build
and java -jar /some/build/libs/app.jar
. I can get api documents generated by spring rest docs at example.com/docs/asciidocname.html
.
but docker image with ./gradlew jib
does not contain this url.
I want to get Api Document that is generated by Spring Rest Docs When i do ./gradlew jib
the below is a part of my build.gradle
plugins {
id "org.asciidoctor.convert" version "2.4.0"
id "com.google.cloud.tools.jib" version "2.5.0"
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
querydsl.extendsFrom compileClasspath
asciidoctor
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
sourceCompatibility = '11'
dependencies {
/**
* RestDocs
*/
asciidoctor 'org.springframework.restdocs:spring-restdocs-asciidoctor'
testImplementation('org.springframework.restdocs:spring-restdocs-mockmvc')
}
test {
useJUnitPlatform {
includeEngines 'junit-jupiter'
}
}
/*************************
* Rest Docs
*************************/
asciidoctor {
dependsOn test
}
bootJar {
dependsOn asciidoctor
from ("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
}
You have configured the
bootJar
task to depend on theasciidoctor
task and include the generated HTML files:Jib doesn't use the jar file when it's building the container image so you need to add similar configuration to Jib.
Let's look at getting it to include the generated HTML first. It provides an extension, named
jib
, where you can useextraDirectories
to do this:You can learn more about adding files to the image that Jib generates in the documentation for its Gradle plugin.
Now we need to configure the
jib
task to depend on theasciidoctor
task. This ensures that the HTML has been generated before Jib tries to include it in the image. As both the extension and the task are namedjib
, we need to explicitly refer to the task:If you ever build the image to your local Docker daemon, you may want similar configuration for the
jibDockerBuild
task as well: