Spring Rest Doc 未生成 html
Spring Rest Doc not producing html
我按照 getting started guide for Spring Rest Doc 一个字一个字地看,但我无法从生成的片段中得到任何 html。
片段在我配置的目录中生成良好(build/generated-snippets),但我看不到任何 html5/ 目录 html 文件由片段生成。
文档 at some point 说明了如何将文档打包到 jar 中,很明显它需要一些文件在 html5/ 目录中,但是当构建运行:
dependsOn asciidoctor
from("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
我错过了什么?
我的项目文件,build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE'
}
}
plugins {
id 'org.asciidoctor.convert' version '1.5.2'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'war'
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext {
snippetsDir = file('build/generated-snippets')
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web:1.3.5.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-logging:1.3.5.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.3.5.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-rest:1.3.5.RELEASE'
compile 'org.springframework.cloud:spring-cloud-starter-aws:1.1.0.RELEASE'
compile 'org.postgresql:postgresql:9.4.1208'
compile 'commons-io:commons-io:2.5'
testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:1.1.0.RELEASE'
testCompile 'org.springframework.restdocs:spring-restdocs-core:1.1.0.RELEASE'
testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.5.RELEASE'
}
jacoco {
toolVersion = "0.7.6.201602180812"
reportsDir = file("$buildDir/customJacocoReportDir")
}
test {
outputs.dir snippetsDir
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpFile = file("$buildDir/jacoco/classpathdumps")
}
}
asciidoctor {
attributes 'snippets': snippetsDir
inputs.dir snippetsDir
dependsOn test
}
war {
dependsOn asciidoctor
from("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
baseName = project_name
version = version
manifest {
attributes(
'Implementation-Title': project_name,
'Implementation-Version': version
)
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.13'
}
还有一个我用来测试的简单测试文件:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
public class ApiDocumentation
{
@Rule
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/generated-snippets");
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp()
{
mockMvc = MockMvcBuilders.webAppContextSetup(context)
.apply(documentationConfiguration(restDocumentation))
.build();
}
@Test
public void testIndex() throws Exception
{
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("index"));
}
}
在 src/main/asciidoc
(Maven) 或 src/docs/asciidoc
(Gradle) 下创建一个 .adoc 文件 (如 api-guide.adoc)生成的片段。然后会在指定目录下生成html.
使用:{spring-restdocs.version}
代替 {project-version}
然后更新项目。
看起来像这样,
dependencies {
asciidoctor 'org.springframework.restdocs:spring-restdocs-asciidoctor:{spring-restdocs.version}'
testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:{spring-restdocs.version}'
}
之后,
项目 > 右键单击 > maven > 更新项目。
然后重新构建项目。希望这能解决您的问题。
我按照 getting started guide for Spring Rest Doc 一个字一个字地看,但我无法从生成的片段中得到任何 html。
片段在我配置的目录中生成良好(build/generated-snippets),但我看不到任何 html5/ 目录 html 文件由片段生成。
文档 at some point 说明了如何将文档打包到 jar 中,很明显它需要一些文件在 html5/ 目录中,但是当构建运行:
dependsOn asciidoctor
from("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
我错过了什么?
我的项目文件,build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.5.RELEASE'
}
}
plugins {
id 'org.asciidoctor.convert' version '1.5.2'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'war'
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext {
snippetsDir = file('build/generated-snippets')
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web:1.3.5.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-logging:1.3.5.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-jpa:1.3.5.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-rest:1.3.5.RELEASE'
compile 'org.springframework.cloud:spring-cloud-starter-aws:1.1.0.RELEASE'
compile 'org.postgresql:postgresql:9.4.1208'
compile 'commons-io:commons-io:2.5'
testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:1.1.0.RELEASE'
testCompile 'org.springframework.restdocs:spring-restdocs-core:1.1.0.RELEASE'
testCompile 'org.springframework.boot:spring-boot-starter-test:1.3.5.RELEASE'
}
jacoco {
toolVersion = "0.7.6.201602180812"
reportsDir = file("$buildDir/customJacocoReportDir")
}
test {
outputs.dir snippetsDir
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpFile = file("$buildDir/jacoco/classpathdumps")
}
}
asciidoctor {
attributes 'snippets': snippetsDir
inputs.dir snippetsDir
dependsOn test
}
war {
dependsOn asciidoctor
from("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
baseName = project_name
version = version
manifest {
attributes(
'Implementation-Title': project_name,
'Implementation-Version': version
)
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.13'
}
还有一个我用来测试的简单测试文件:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
public class ApiDocumentation
{
@Rule
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build/generated-snippets");
@Autowired
private WebApplicationContext context;
private MockMvc mockMvc;
@Before
public void setUp()
{
mockMvc = MockMvcBuilders.webAppContextSetup(context)
.apply(documentationConfiguration(restDocumentation))
.build();
}
@Test
public void testIndex() throws Exception
{
mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(document("index"));
}
}
在 src/main/asciidoc
(Maven) 或 src/docs/asciidoc
(Gradle) 下创建一个 .adoc 文件 (如 api-guide.adoc)生成的片段。然后会在指定目录下生成html.
使用:{spring-restdocs.version}
代替 {project-version}
然后更新项目。
看起来像这样,
dependencies {
asciidoctor 'org.springframework.restdocs:spring-restdocs-asciidoctor:{spring-restdocs.version}'
testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:{spring-restdocs.version}'
}
之后, 项目 > 右键单击 > maven > 更新项目。
然后重新构建项目。希望这能解决您的问题。