java - Spring Rest DocはHTMLを生成しません
Spring Rest Doc 入門ガイドを一語一語たどりましたが、生成されたスニペットから html を取得できません。
スニペットは設定したディレクトリ (build/generated-snippets) に正しく生成されますが、スニペットから生成された html ファイルを含む html5/ ディレクトリが表示されません。
ある時点で、ドキュメントはドキュメントをコンテナにパッケージ化するために何をすべきかを述べており、いくつかのファイルがディレクトリにあることを期待していることは明らかですhtml5/ ectorio ですが、ビルドの実行時に作成されません:
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がディレクトリに生成されます
------------に答える------------
使用: {project-version} の代わりに {spring-restdocs.version} その後、プロジェクトを更新してください。
次のようになります。
dependencies {
asciidoctor 'org.springframework.restdocs:spring-restdocs-asciidoctor:{spring-restdocs.version}'
testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:{spring-restdocs.version}'
}
その後、 プロジェクト > 右クリック > エキスパート > プロジェクトの更新
次に、プロジェクトを再構築します。これで問題が解決することを願っています。
タグ:
関連記事:
python - Djangoのpre_save信号:挿入か更新かを知るにはどうすればよいですか?
java: GSM モジュールからサーバーにデータを送信し、Android フォンからデータを取得する