Spring Boot 2.3.x の Web アプリを 2.4.x へバージョンアップする ( その4 )( Release Notes を見て必要な箇所を変更する。。。ことがなさそうなので Checkstyle を 8.35 → 8.41 へバージョンアップする )
概要
記事一覧はこちらです。
Spring Boot 2.3.x の Web アプリを 2.4.x へバージョンアップする ( その3 )( Spring Boot を 2.3.9 → 2.4.3 へバージョンアップする ) の続きです。
- 今回の手順で確認できるのは以下の内容です。
- 以下のドキュメントを見て必要な箇所を変更します。。。と思ったのですが、記述が多い割に今回は変更が必要なところがありませんでした。
- Checkstyle を 8.35 → 8.41 へバージョンアップします。
- 最新版の google_checks.xml の内容も反映します。
参照したサイト・書籍
checkstyle / checkstyle
https://github.com/checkstyle/checkstylecheckstyle/checkstyle - checkstyle/src/main/resources/google_checks.xml
https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
目次
- build.gradle を変更する
- IntelliJ IDEA の CheckStyle-IDEA Plugin が使用する Checkstyle のバージョンを 8.34 に変更する
- 最新版の google_checks.xml から設定をコピーする
- 今回 google_checks.xml に追加した COMPACT_CTOR_DEF とは?
手順
build.gradle を変更する
checkstyle { configFile = file("${rootProject.projectDir}/config/checkstyle/google_checks.xml") toolVersion = "8.41" sourceSets = [project.sourceSets.main] }
toolVersion = "8.35"
→toolVersion = "8.41"
に変更します。
Gradle Tool Window の左上にある「Refresh all Gradle projects」ボタンをクリックして更新した後、clean タスク実行 → Rebuild Project 実行 → build タスクを実行すると BUILD SUCCESSFUL が表示されましたが、以下の WARNING も出力されました。
[ant:checkstyle] [WARN] D:\project-springboot\ksbysample-webapp-lending\src\main\java\ksbysample\webapp\lending\util\doma\ComponentAndAutowiredDomaConfig.java:13:9: 'annotation array initialization' の子のインデントレベル 8 は正しくありません。期待されるレベルは 4 です。 [Indentation]
該当箇所を見てみると確かにインデントが 8 でした。
今はこのままにして、google_checks.xml を変更する時に対応します。
IntelliJ IDEA の CheckStyle-IDEA Plugin が使用する Checkstyle のバージョンを 8.40 に変更する
CheckStyle-IDEA Plugin に指定できるバージョンが 8.40 までだったので 8.40 を指定します。
最新版の google_checks.xml から設定をコピーする
最新版の google_checks.xml から差分を反映します。今回反映した内容を箇条書きで記述しておきます。
<module name="LeftCurly">
の<property name="tokens">
の value に COMPACT_CTOR_DEF を追加しました。<module name="RightCurly">
の<property name="tokens">
の value に COMPACT_CTOR_DEF を追加しました。<module name="WhitespaceAround">
に<property name="ignoreEnhancedForColon" value="false"/>
を追加しました。<module name="EmptyLineSeparator">
の<property name="tokens">
の value に COMPACT_CTOR_DEF を追加しました。<module name="PatternVariableName">...</module>
を追加しました。<module name="Indentation">
の<property name="arrayInitIndent" value="4"/>
→<property name="arrayInitIndent" value="8"/>
に変更しました。上で出力された WARNING はこれで解消します。<module name="AnnotationLocation">
の<property name="tokens">
の value に COMPACT_CTOR_DEF を追加しました。<module name="RequireEmptyLineBeforeBlockTagGroup"/>
を追加しました。<module name="JavadocMethod">
の<property name="tokens">
の value に COMPACT_CTOR_DEF を追加しました。<module name="MissingJavadocMethod">
の<property name="tokens">
の value に COMPACT_CTOR_DEF を追加しました。<module name="MissingJavadocType">...</module>
を追加しました。ただし<property name="tokens">
の value から RECORD_DEF は削除しました。
clean タスク実行 → Rebuild Project 実行 → build タスクを実行すると BUILD SUCCESSFUL が表示されましたが、WARNING も大量に出力されました。以下の点を変更します。
Javadoc コメントがありません。 [MissingJavadocType]
- 以前は WARNING が出なかった箇所も指摘してくれるようになったようです。Javadoc コメントを追加します。
Javadoc tag '@return' の前には空の行が必要です。 [RequireEmptyLineBeforeBlockTagGroup]
- Doma 2 で自動生成した Entity クラスで WARNING が出ていました。Ctrl+Alt+L でフォーマットすると解消されます。
再度 clean タスク実行 → Rebuild Project 実行 → build タスクを実行すると WARNING が出なくなりました。
今回 google_checks.xml に追加した COMPACT_CTOR_DEF とは?
https://checkstyle.sourceforge.io/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html
には A compact canonical constructor eliminates the list of formal parameters; they are declared implicitly.
と記述されています。
同じページ内にある For example:
のサンプルを見ると Java 14 からの Record 構文用の設定のようです。今回は RECORD_DEF のようにエラーや警告は出ないので追加したままにします。
public record myRecord () { public myRecord{} }
履歴
2021/03/03
初版発行。
Spring Boot 2.3.x の Web アプリを 2.4.x へバージョンアップする ( その3 )( Spring Boot を 2.3.9 → 2.4.3 へバージョンアップする )
概要
記事一覧はこちらです。
- 今回の手順で確認できるのは以下の内容です。
- Spring Boot を 2.3.9 → 2.4.3 へバージョンアップします。
参照したサイト・書籍
目次
手順
Spring Initializr で 2.4.3 のプロジェクトを作成する
Spring Initializr で 2.4.3 のプロジェクトを作成して、生成された build.gradle を見て反映した方が良い点があるか確認します。
以下の build.gradle が作成されました。
plugins { id 'org.springframework.boot' version '2.4.3' id 'io.spring.dependency-management' version '1.0.11.RELEASE' id 'java' } group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '11' configurations { compileOnly { extendsFrom annotationProcessor } } repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-redis' implementation 'org.springframework.boot:spring-boot-starter-freemarker' implementation 'org.springframework.boot:spring-boot-starter-mail' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.session:spring-session-data-redis' implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5' compileOnly 'org.projectlombok:lombok' developmentOnly 'org.springframework.boot:spring-boot-devtools' runtimeOnly 'org.postgresql:postgresql' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' } test { useJUnitPlatform() }
今回は反映した方が良さそうな点はありませんでした。
build.gradle を変更する
buildscript { ext { group "ksbysample" version "2.4.3" } repositories { mavenCentral() maven { url "https://repo.spring.io/release/" } gradlePluginPortal() } dependencies { // for doma-codegen-plugin classpath "org.postgresql:postgresql:42.2.19" } } plugins { id "java" id "eclipse" id "idea" id "org.springframework.boot" version "2.4.3" id "io.spring.dependency-management" version "1.0.11.RELEASE" id "groovy" id "checkstyle" id "com.github.spotbugs" version "4.5.0" id "pmd" id "net.ltgt.errorprone" version "1.2.1" id "com.gorylenko.gradle-git-properties" version "2.2.4" id "org.seasar.doma.codegen" version "1.2.1" } sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 wrapper { gradleVersion = "6.8.3" distributionType = Wrapper.DistributionType.ALL } [compileJava, compileTestGroovy, compileTestJava]*.options*.encoding = "UTF-8" [compileJava, compileTestGroovy, compileTestJava]*.options*.compilerArgs = ["-Xlint:all,-options,-processing,-path"] tasks.withType(JavaCompile).configureEach { options.errorprone.disableWarningsInGeneratedCode = true } tasks.named("compileTestJava").configure { options.errorprone.enabled = false } // for Doma 2 // Copy the resources referred by the Doma annotation processors to // the destinationDir of the compileJava task task copyDomaResources(type: Sync) { from sourceSets.main.resources.srcDirs into compileJava.destinationDir include "doma.compile.config" include "META-INF/**/*.sql" include "META-INF/**/*.script" } compileJava.dependsOn copyDomaResources springBoot { buildInfo() } idea { module { inheritOutputDirs = false outputDir = file("$buildDir/classes/main/") } } configurations { compileOnly.extendsFrom annotationProcessor // annotationProcessor と testAnnotationProcessor、compileOnly と testCompileOnly を併記不要にする testAnnotationProcessor.extendsFrom annotationProcessor testImplementation.extendsFrom compileOnly // for SpotBugs spotbugsStylesheets { transitive = false } } checkstyle { configFile = file("${rootProject.projectDir}/config/checkstyle/google_checks.xml") toolVersion = "8.35" sourceSets = [project.sourceSets.main] } spotbugs { toolVersion = "4.1.1" ignoreFailures = true spotbugsTest.enabled = false } spotbugsMain { reports { html { enabled = true stylesheet = "color.xsl" } } } pmd { toolVersion = "6.26.0" sourceSets = [project.sourceSets.main] ignoreFailures = true consoleOutput = true ruleSetFiles = rootProject.files("/config/pmd/pmd-project-rulesets.xml") ruleSets = [] } repositories { mavenCentral() } dependencyManagement { imports { // mavenBom は以下の URL のものを使用する // https://repo.spring.io/release/org/springframework/boot/spring-boot-starter-parent/2.2.9.RELEASE/ // bomProperty に指定可能な property は以下の URL の BOM に記述がある // https://repo.spring.io/release/org/springframework/boot/spring-boot-dependencies/2.2.9.RELEASE/spring-boot-dependencies-2.2.9.RELEASE.pom mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES) { // Spring Boot の BOM に定義されているバージョンから変更する場合には、ここに以下のように記述する // bomProperty "thymeleaf.version", "3.0.9.RELEASE" bomProperty "groovy.version", "2.5.12" } mavenBom("org.junit:junit-bom:5.7.1") } } dependencies { def jdbcDriver = "org.postgresql:postgresql:42.2.19" def spockVersion = "1.3-groovy-2.5" def domaVersion = "2.45.0" def lombokVersion = "1.18.18" def errorproneVersion = "2.4.0" def powermockVersion = "2.0.9" def spotbugsVersion = "4.1.1" // dependency-management-plugin によりバージョン番号が自動で設定されるもの // Appendix F. Dependency versions ( https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-dependency-versions.html ) 参照 implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-validation") implementation("org.springframework.boot:spring-boot-starter-thymeleaf") implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity5") implementation("org.springframework.boot:spring-boot-starter-data-jpa") implementation("org.springframework.boot:spring-boot-starter-freemarker") implementation("org.springframework.boot:spring-boot-starter-mail") implementation("org.springframework.boot:spring-boot-starter-security") implementation("org.springframework.boot:spring-boot-starter-data-redis") implementation("org.springframework.boot:spring-boot-starter-amqp") implementation("org.springframework.boot:spring-boot-starter-actuator") developmentOnly("org.springframework.boot:spring-boot-devtools") compileOnly("org.springframework.boot:spring-boot-configuration-processor") implementation("org.springframework.session:spring-session-data-redis") implementation("org.springframework.retry:spring-retry") implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml") implementation("org.apache.commons:commons-lang3") implementation("org.codehaus.janino:janino") implementation("io.micrometer:micrometer-registry-prometheus") testImplementation("org.springframework.boot:spring-boot-starter-test") { exclude group: "org.junit.vintage", module: "junit-vintage-engine" } testImplementation("org.springframework.security:spring-security-test") testImplementation("org.yaml:snakeyaml") // dependency-management-plugin によりバージョン番号が自動で設定されないもの、あるいは最新バージョンを指定したいもの runtimeOnly("${jdbcDriver}") implementation("com.integralblue:log4jdbc-spring-boot-starter:2.0.0") implementation("org.simpleframework:simple-xml:2.7.1") implementation("com.univocity:univocity-parsers:2.9.1") implementation("com.google.guava:guava:30.1-jre") implementation("org.flywaydb:flyway-core:7.5.4") testImplementation("org.dbunit:dbunit:2.7.0") { exclude group: "postgresql", module: "postgresql" } testImplementation("com.icegreen:greenmail:1.6.2") testImplementation("org.assertj:assertj-core:3.19.0") testImplementation("com.jayway.jsonpath:json-path:2.5.0") testImplementation("org.jsoup:jsoup:1.13.1") testImplementation("cglib:cglib-nodep:3.3.0") testImplementation("org.spockframework:spock-core:${spockVersion}") testImplementation("org.spockframework:spock-spring:${spockVersion}") // for lombok // testAnnotationProcessor、testCompileOnly を併記しなくてよいよう configurations で設定している annotationProcessor("org.projectlombok:lombok:${lombokVersion}") compileOnly("org.projectlombok:lombok:${lombokVersion}") // for Doma implementation("org.seasar.doma:doma-core:${domaVersion}") implementation("org.seasar.doma:doma-slf4j:${domaVersion}") annotationProcessor("org.seasar.doma:doma-processor:${domaVersion}") // for JUnit 5 // junit-jupiter で junit-jupiter-api, junit-jupiter-params, junit-jupiter-engine の3つが依存関係に追加される testImplementation("org.junit.jupiter:junit-jupiter") testRuntimeOnly("org.junit.platform:junit-platform-launcher") // for Error Prone ( http://errorprone.info/ ) errorprone("com.google.errorprone:error_prone_core:${errorproneVersion}") compileOnly("com.google.errorprone:error_prone_annotations:${errorproneVersion}") // PowerMock testImplementation("org.powermock:powermock-module-junit4:${powermockVersion}") testImplementation("org.powermock:powermock-api-mockito2:${powermockVersion}") // for SpotBugs spotbugs("com.github.spotbugs:spotbugs:${spotbugsVersion}") compileOnly("com.github.spotbugs:spotbugs-annotations:${spotbugsVersion}") spotbugsPlugins("com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1") } ..........
Spring Boot 2.4.3 へのバージョンアップとして以下の点を変更します。
- buildscript block の以下の点を変更します。
version "2.3.9-RELEASE"
→version "2.4.3"
- plugins block の以下の点を変更します。
id "org.springframework.boot" version "2.3.9.RELEASE"
→id "org.springframework.boot" version "2.4.3"
各種ライブラリのバージョンアップとして以下の点を変更します。
- buildscript block の以下の点を変更します。
classpath "org.postgresql:postgresql:42.2.14"
→classpath "org.postgresql:postgresql:42.2.19"
- plugins block の以下の点を変更します。
id "com.gorylenko.gradle-git-properties" version "2.2.3"
→id "com.gorylenko.gradle-git-properties" version "2.2.4"
- dependencyManagement block の以下の点を変更します。
mavenBom("org.junit:junit-bom:5.7.0")
→mavenBom("org.junit:junit-bom:5.7.1")
- dependencies block の以下の点を変更します。
def jdbcDriver = "org.postgresql:postgresql:42.2.14"
→def jdbcDriver = "org.postgresql:postgresql:42.2.19"
def domaVersion = "2.44.3"
→def domaVersion = "2.45.0"
def lombokVersion = "1.18.12"
→def lombokVersion = "1.18.18"
def powermockVersion = "2.0.7"
→def powermockVersion = "2.0.9"
implementation("com.univocity:univocity-parsers:2.8.4")
→implementation("com.univocity:univocity-parsers:2.9.1")
implementation("com.google.guava:guava:29.0-jre")
→implementation("com.google.guava:guava:30.1-jre")
implementation("org.flywaydb:flyway-core:6.5.3")
→implementation("org.flywaydb:flyway-core:7.5.4")
testImplementation("com.icegreen:greenmail:1.5.14")
→testImplementation("com.icegreen:greenmail:1.6.2")
testImplementation("org.assertj:assertj-core:3.16.1")
→testImplementation("org.assertj:assertj-core:3.19.0")
testImplementation("com.jayway.jsonpath:json-path:2.4.0")
→testImplementation("com.jayway.jsonpath:json-path:2.5.0")
clean タスク実行 → Rebuild Project 実行 → build タスクを実行すると "BUILD SUCCESSFUL" のメッセージが出力されました。
履歴
2021/02/28
初版発行。
Spring Boot 2.3.x の Web アプリを 2.4.x へバージョンアップする ( その2 )( Spring Boot を 2.3.7 → 2.3.9 へ、Gradle を 6.5.1 → 6.8.3 へバージョンアップする )
概要
記事一覧はこちらです。
Spring Boot 2.3.x の Web アプリを 2.4.x へバージョンアップする ( その1 )( 概要 ) の続きです。
- 今回の手順で確認できるのは以下の内容です。
- Spring Boot のバージョンを 2.3 系の最新バージョンである 2.3.9 へ、Gradle のバージョンを 6.x 系の最新バージョンである 6.8.3 に上げて build できることを確認します。
- 今回は問題がなければライブラリはバージョンアップしません。
参照したサイト・書籍
目次
手順
2.3.x ブランチの作成
master から 2.4.x ブランチを、2.4.x から feature/136-issue ブランチを作成します。
Spring Boot を 2.3.7 → 2.3.9 にバージョンアップする
build.gradle の以下の点を変更します。
buildscript { ext { group "ksbysample" version "2.3.9-RELEASE" } repositories { mavenCentral() maven { url "https://repo.spring.io/release/" } gradlePluginPortal() } dependencies { // for doma-codegen-plugin classpath "org.postgresql:postgresql:42.2.14" } } plugins { id "java" id "eclipse" id "idea" id "org.springframework.boot" version "2.3.9.RELEASE" id "io.spring.dependency-management" version "1.0.11.RELEASE" id "groovy" id "checkstyle" id "com.github.spotbugs" version "4.5.0" id "pmd" id "net.ltgt.errorprone" version "1.2.1" id "com.gorylenko.gradle-git-properties" version "2.2.3" id "org.seasar.doma.codegen" version "1.2.1" } ..........
- buildscript block の以下の点を変更します。
version "2.3.7-RELEASE"
→version "2.3.9-RELEASE"
- plugins block の以下の点を変更します。
id "org.springframework.boot" version "2.3.7.RELEASE"
→id "org.springframework.boot" version "2.3.9.RELEASE"
id "io.spring.dependency-management" version "1.0.10.RELEASE"
→id "io.spring.dependency-management" version "1.0.11.RELEASE"
Gradle Tool Window の左上にある「Refresh all Gradle projects」ボタンをクリックして更新します。
Gradle を 6.5.1 → 6.8.3 にバージョンアップする
build.gradle の wrapper タスクの記述を以下のように変更します。
wrapper {
gradleVersion = "6.8.3"
distributionType = Wrapper.DistributionType.ALL
}
gradleVersion = "6.5.1"
→gradleVersion = "6.8.3"
に変更します。
コマンドプロンプトから gradlew wrapper --gradle-version=6.8.3
、gradlew --version
コマンドを実行します。
gradle/wrapper/gradle-wrapper.properties は以下の内容になります。
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists
JVM を呼び出す時のメモリ割り当ての記述が元に戻りますが gradlew.bat 内の記述はそのままにします。
Gradle Tool Window の左上にある「Refresh all Gradle projects」ボタンをクリックして更新します。
.gradle ディレクトリの下にバージョン番号のディレクトリがあるので、6.8.3 以外を削除します。
clean タスク実行 → Rebuild Project 実行 → build タスクを実行すると "BUILD SUCCESSFUL" のメッセージが出力されました。
履歴
2021/02/28
初版発行。
Spring Boot 2.3.x の Web アプリを 2.4.x へバージョンアップする ( その1 )( 概要 )
概要
記事一覧はこちらです。
- 「Spring Boot で書籍の貸出状況確認・貸出申請する Web アプリケーションを作る」で作成した Web アプリケーション ( ksbysample-webapp-lending ) の Spring Boot のバージョンを 2.3.7 → 2.4.x へバージョンアップします。
- 進め方は以下の方針とします。
- Git のブランチは 2.4.x を作成して、そちらで作業します。Spring Boot のバージョンと合わせます。
- Spring Boot のバージョンを 2.3 系の最新バージョンである 2.3.9 へ、Gradle のバージョンを 6.x 系の最新バージョンである 6.8.3 に上げて build できることを確認します。この時点ではライブラリはバージョンアップしません。
- Spring Boot のバージョンを 2.4.x にします。
- Spring Initializr で 2.4.x のプロジェクトを作成して、修正した方がよさそうな点があれば反映します。
- ライブラリは最新バージョンにアップデートします。ただし、この時点では checkstyle, spotbugs, pmd, Error Prone のバージョンは上げません。
- プロジェクトを build し直してエラーが出る点があれば修正し、まずはここまでで動くようにします。
- その後で 2.4 系ではこう書くべきという点があるか確認し、変更した方がよいところを変更します。
- checkstyle, spotbugs, pmd, Error Prone を1つずつ最新バージョンに上げます。変更した方がよいところがあれば変更します。
- docker-compose で使用している image を最新バージョンに上げます。
- 今回のバージョンアップで Redis 6+lettuce-core 6 の構成になるので、Redis 6 の新機能を試してみます。
2.4 の Release Notes はこちらです。
Spring Boot 2.4 Release Notes
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.4-Release-Notes
また Spring Framework も 5.3 にバージョンアップされているとのこと。
What's New in Version 5.3
https://github.com/spring-projects/spring-framework/wiki/What%27s-New-in-Spring-Framework-5.x#whats-new-in-version-53
履歴
2021/02/28
初版発行。
Spring Boot 2.3.x の Web アプリを 2.4.x へバージョンアップする ( 大目次 )
- その1 ( 概要 )
- その2 ( Spring Boot を 2.3.7 → 2.3.9 へ、Gradle を 6.5.1 → 6.8.3 へバージョンアップする )
- その3 ( Spring Boot を 2.3.9 → 2.4.3 へバージョンアップする )
- その4 ( Release Notes を見て必要な箇所を変更する。。。ことがなさそうなので Checkstyle を 8.35 → 8.41 へバージョンアップする )
- その5 ( PMD を 6.26.0 → 6.32.0 へバージョンアップする )
- その6 ( Error Prone を 2.4.0 → 2.5.1 へバージョンアップする )
- その7 ( SpotBugs を 4.1.1 → 4.2.1 へバージョンアップする )
- その8 ( Docker コンテナの image をバージョンアップする )
- その9 ( RedisClusterConfig の RedisConnectionFactory Bean を削除し、application.properties で設定する方法に切り替える )
- その10 ( Docker で複数の Tomcat を起動して動作確認する )
- 感想
- その11 ( exclude junit-vintage-engine の記述を削除する+domaGen タスクで SQL ファイルが作成されない問題を解消する )
Antora で PlantUML 等の diagram を埋め込む
Translate to English
https://translate.google.com/translate?sl=auto&tl=en&u=https%3A%2F%2Fksby.hatenablog.com%2Fentry%2F2021%2F02%2F13%2F194234
概要
記事一覧はこちらです。
Antora でも Kroki を利用して PlantUML 等の diagram を埋め込んでみます。
参照したサイト・書籍
Mogztter / asciidoctor-kroki
https://github.com/Mogztter/asciidoctor-krokiAsciiDoc Keys
https://docs.antora.org/antora/2.3/playbook/configure-asciidoc/#extensions
目次
- ksbysample-antora-playbook プロジェクトに Kroki のコンテナを起動するための docker-compose.yml をコピーしてコンテナを起動する
- ksbysample-antora プロジェクトに diagram のファイルと adoc ファイルをコピーする
- ksbysample-antora-playbook プロジェクトに asciidoctor-kroki をインストールする
npx antora --fetch antora-playbook.yml
を実行してドキュメントサイトを生成する
手順
ksbysample-antora-playbook プロジェクトに Kroki のコンテナを起動するための docker-compose.yml をコピーしてコンテナを起動する
ksbysample-asciidoctor プロジェクトに docker-compose.yml を作成し、Kroki のコンテナを起動するための設定を記述する で作成した docker-compose.yml を ksbysample-antora-playbook プロジェクトのルートディレクトリ直下にコピーします。
docker-compose up -d
コマンドを実行し、Kroki のコンテナを起動します。
ksbysample-antora プロジェクトに diagram のファイルと adoc ファイルをコピーする
v3.0 ブランチを作成し、ksbysample-asciidoctor プロジェクトから 03_diagram ディレクトリのファイルを にコピーする
main ブランチから v3.0 ブランチを作成します。
ksbysample-asciidoctor プロジェクトから 03_diagram ディレクトリのファイルをコピーします。adoc ファイルは pages ディレクトリの下にコピーし、diagram のファイルは images ディレクトリの下にコピーします(Hierarchy and reserved names に attachments や partials のディレクトリが記述されていますが diagram は svg になるので images ディレクトリにしました)。
- modules/ROOT/pages の下に 03_diagram ディレクトリを作成します。
- ksbysample-asciidoctor プロジェクトの src/docs/asciidoc/03_diagram/index.adoc を modules/ROOT/pages の下にコピーします。
- modules/ROOT/images の下に 03_diagram ディレクトリを作成します。
- modules/ROOT/images/03_diagram の下に ksbysample-asciidoctor プロジェクトの src/docs/asciidoc/03_diagram の下の diagram のファイルをコピーします。
- src/docs/asciidoc/03_diagram/example-bpmn.xml
- src/docs/asciidoc/03_diagram/example-bytefield.clj
- src/docs/asciidoc/03_diagram/example-c4model.puml
- src/docs/asciidoc/03_diagram/example-class.puml
- src/docs/asciidoc/03_diagram/example-ditaa.txt
- src/docs/asciidoc/03_diagram/example-sequence.puml
- modules/ROOT/images の下に 02_include ディレクトリを作成し、modules/ROOT/images の下の以下のファイルを移動します。
コピー後のディレクトリ構成は以下のようになります。
この時点では modules/ROOT/pages/03_diagram/index.adoc に赤波下線が出ており、AsciiDoc Plugin の preview にまだ diagram は表示されません。
modules/ROOT/pages/03_diagram/index.adoc を変更する
AsciiDoc Plugin の preview に diagram が表示されるよう modules/ROOT/pages/03_diagram/index.adoc を変更します。
Antora の Document の Include a Page を参考に、今回 diagram のファイルは images ディレクトリの下に配置したので include::example-sequence.puml[]
→ include::image$03_diagram/example-sequence.puml[]
のように image$03_diagram/
を追加します(ディレクトリ名の末尾の s
を取り除いて $
を追加した文字列を付けると、そのディレクトリの下のファイルを参照できます)。
= AsciiDoc 形式のドキュメントに PlantUML の図を埋め込む Doc Writer <doc@example.com> :lang: ja == シーケンス図 [plantuml] .... include::image$03_diagram/example-sequence.puml[] .... == クラス図 [plantuml] .... include::image$03_diagram/example-class.puml[] .... == BPMN [bpmn] .... include::image$03_diagram/example-bpmn.xml[] .... == bytefield [bytefield] .... include::image$03_diagram/example-bytefield.clj[] .... == ditaa [ditaa] .... include::image$03_diagram/example-ditaa.txt[] .... == C4 model with PlantUML [plantuml] .... include::image$03_diagram/example-c4model.puml[] ....
そうすると adoc ファイル内の赤波下線が消えて AsciiDoc Plugin の preview に diagram が表示されるようになります。
modules/ROOT/pages/02_include/01.adoc を変更する
01-01.png ~ 01-03.png の画像ファイルを modules/ROOT/images/02_include の下へ移動したので modules/ROOT/pages/02_include/01.adoc の image::...
のパスを image::01-01.png
→ 02_include/image::01-01.png
のように変更します。
.......... Shift キーを2回押してダイアログを表示した後、「Git」タブを選択してから `redis`(commit message にこの文字列が入力されているものがあります)と入力してみましたが、何も表示されず。。。 image::02_include/01-01.png[,420,423] ダイアログ右上の「Filter」ボタンをクリックすると「Commit by hash」しかチェックされていませんでした。 image::02_include/01-02.png[,558,158] 「All」ボタンをクリックして全てチェックすると commit message も検索してヒットしたものが表示されるようになりました。 image::02_include/01-03.png[,562,179]
こちらも AsciiDoc Plugin の preview に画像が表示されました。
modules/ROOT/nav.adoc を変更する
modules/ROOT/nav.adoc に modules/ROOT/pages/03_diagram/index.adoc へのリンク(.AsciiDoc 形式のドキュメントに PlantUML の図を埋め込む
以降の記述)を追加します。
* xref:ROOT:01_simple/index.adoc[Hello, AsciiDoc!] .include directive で章毎にファイルを分けてみる * xref:ROOT:02_include/01.adoc[IntelliJ IDEA 2020.3 新機能メモ書き] * xref:ROOT:02_include/02.adoc[Asciidoctor+Gradle の環境で AsciiDoc 形式のドキュメントから HTML ファイルを生成してみる] .AsciiDoc 形式のドキュメントに PlantUML の図を埋め込む * xref:ROOT:03_diagram/index.adoc[サンプル]
antora.yml を変更する
antora.yml の version の記述を v2.0
→ v3.0
に変更します。
name: ksbysample-antora title: ksbysample-antora version: v3.0 start_page: ROOT:01_simple/index.adoc nav: - modules/ROOT/nav.adoc
v3.0 ブランチを main ブランチへマージする
v3.0 ブランチを main ブランチへマージします。
ksbysample-antora-playbook プロジェクトに asciidoctor-kroki をインストールする
npm install --save-dev asciidoctor-kroki
を実行する
Antora から Kroki のコンテナにアクセスするには asciidoctor-kroki を使用します。
ksbysample-antora-playbook プロジェクトで npm install --save-dev asciidoctor-kroki
コマンドを実行してインストールします。
antora-playbook.yml を変更する
antora-playbook.yml で branches: [v2.0, v1.0]
→ branches: [v2.0, v1.0]
に変更し、asciidoctor-kroki を利用するために asciidoc:
の行以降の記述を追加します。
site: title: ksbysample-document-site start_page: ksbysample-antora::01_simple/index.adoc content: sources: - url: https://github.com/ksby/ksbysample-antora.git branches: [v3.0, v2.0, v1.0] ui: bundle: url: https://gitlab.com/antora/antora-ui-default/-/jobs/artifacts/master/raw/build/ui-bundle.zip?job=bundle-stable snapshot: true asciidoc: attributes: kroki-server-url: http://localhost:8000 kroki-fetch-diagram: true extensions: - asciidoctor-kroki
npx antora --fetch antora-playbook.yml
を実行してドキュメントサイトを生成する
npx antora --fetch antora-playbook.yml
を実行すると、Skipping preprocessing of PlantUML include, because reading the referenced ...
というメッセージが出力されました。
modules/ROOT/images/03_diagram/example-c4model.puml を開いてみると、先頭に以下の記述があり、
@startuml "messagebus" !include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml ' uncomment the following line and comment the first to use locally ' !include C4_Container.puml
https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml を見てみると、以下の記述がありました。
' convert it with additional command line argument -DRELATIVE_INCLUDE="." to use locally !if %variable_exists("RELATIVE_INCLUDE") !include %get_variable_value("RELATIVE_INCLUDE")/C4_Context.puml !else !include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Context.puml !endif
調べてみると、最初は RELATIVE_INCLUDE という環境変数が設定されているから !include %get_variable_value("RELATIVE_INCLUDE")/C4_Context.puml
が実行されていると思ったのですが、PlantUML の !include
は Preprocessing なので最初に全て実行されている(!if ... !endif
で実行されないように判断されるのは Preprocessing の後)だけのようです。
コマンド実行後の build ディレクトリの下のディレクトリ構成は以下のようになっており(Kroki で生成された svg ファイルは _images/03_diagram
の下ではなく _images
の下に生成されていました)、
build/site/index.html を開くと diagram は全て表示されました。
メッセージはエラー出力に出力されているので npx antora --fetch antora-playbook.yml 2>/dev/null
で実行すれば出力されません。
履歴
2021/02/13
初版発行。
AdoptOpenJDK を 11.0.9.1+1 → 11.0.10+9 へ、IntelliJ IDEA を 2020.3.1 → 2020.3.2 へ、Git for Windows を 2.30.0 → 2.30.0.2 へバージョンアップ
AdoptOpenJDK を 11.0.9.1+1 → 11.0.10+9 へバージョンアップする
※ksbysample-webapp-lending プロジェクトを開いた状態でバージョンアップしています。
https://adoptopenjdk.net/ を見ると 11.0.10+9 がダウンロードできるようになっていましたので、11.0.10+9 へバージョンアップします。
インストール時に削除されるかもしれないので D:\Java\jdk-11.0.9.101-hotspot → D:\Java\jdk-11.0.9.101-hotspotx にリネームします。
OpenJDK11U-jdk_x64_windows_hotspot_11.0.10_9.msi をダウンロードして D:\Java\jdk-11.0.10.9-hotspot へインストールした後、環境変数 JAVA_HOME のパスを D:\Java\jdk-11.0.10.9-hotspot へ変更します。
コマンドプロンプトから
java -version
を実行し、11.0.10
に変更されていることを確認します。D:\Java\jdk-11.0.9.101-hotspotx → D:\Java\jdk-11.0.9.101-hotspot に戻します。
IntelliJ IDEA を再起動します。
新規プロジェクトを作成する時に使用する JDK を 11.0.10+9 へ変更しようと思いましたが、IntelliJ IDEA の 2020.3 の新しい「Welcome to IntelliJ IDEA」ダイアログには 「Configure」-「Structure for New Projects」のメニューがありませんでした。
新規プロジェクトを作成する時にはダイアログ右上の「New Project」ボタンをクリックして表示される「New Project」の画面の「Project SDK」で選択すればよいようです。
「Welcome to IntelliJ IDEA」ダイアログで ksbysample-webapp-lending プロジェクトを開いて、プロジェクトが使用する JDK を 11.0.10+9 に変更します。
IntelliJ IDEA のメイン画面が開いたら、メニューから「File」-「Project Structure...」を選択します。
「Project Structure」ダイアログが表示されます。「Project SDK」で D:\Java\jdk-11.0.10.9-hotspot を選択します。
「Project SDK」の「Edit」ボタンをクリックします。
「Project Structure」ダイアログが表示されます。画面左側で「Platform Settings」-「SDKs」を選択して、中央のリストから「11.0.9.101」を選択した後、リストの上の「-」ボタンをクリックして削除します。
中央のリストから「11」を選択した後、"11" → "11.0.10.9" へ変更します。
「OK」ボタンをクリックして「Project Structure for New Projects」ダイアログを閉じます。
メイン画面に戻ると画面右下に「Indexing...」の表示が出るので、終了するまで待ちます。
Gradle Tool Window の左上にある「Refresh all Gradle projects」ボタンをクリックして更新します。
clean タスク実行 → Rebuild Project 実行 → build タスクを実行して、"BUILD SUCCESSFUL" のメッセージが出力されることを確認します。
Project Tool Window で src/test でコンテキストメニューを表示して「Run 'All Tests' with Coverage」を選択し、テストが全て成功することを確認します。
特に問題は発生しませんでした。11.0.10+9 で開発を進めます。
IntelliJ IDEA を 2020.3.1 → 2020.3.2 へバージョンアップする
IntelliJ IDEA の 2020.3.2 がリリースされているのでバージョンアップします。
- IntelliJ IDEA 2020.3.2 Is Available
https://blog.jetbrains.com/idea/2021/01/intellij-idea-2020-3-2/
※ksbysample-webapp-lending プロジェクトを開いた状態でバージョンアップしています。
IntelliJ IDEA のメインメニューから「Help」-「Check for Updates...」を選択します。
「IDE and Plugin Updates」ダイアログが表示されます。右下に「Update and Restart」ボタンが表示されていますので、「Update and Restart」ボタンをクリックします。
Plugin の update も表示されました。このまま「Update and Restart」ボタンをクリックします。
Patch がダウンロードされて IntelliJ IDEA が再起動します。
IntelliJ IDEA が起動すると画面下部に「Indexing」のメッセージが表示されますので、終了するまで待機します。
IntelliJ IDEA のメインメニューから「Help」-「About」を選択し、2020.3.2 へバージョンアップされていることを確認します。
clean タスク実行 → Rebuild Project 実行 → build タスクを実行して、"BUILD SUCCESSFUL" のメッセージが出力されることを確認します。
Project Tool Window で src/test でコンテキストメニューを表示して「Run 'All Tests' with Coverage」を選択し、テストが全て成功することを確認します。
Git for Windows を 2.30.0 → 2.30.0.2 へバージョンアップする
Git for Windows の 2.30.0.2 がリリースされていたのでバージョンアップします。
https://gitforwindows.org/ の「Download」ボタンをクリックして Git-2.30.0.2-64-bit.exe をダウンロードします。
Git-2.30.0.2-64-bit.exe を実行します。
「Git 2.30.0.2 Setup」ダイアログが表示されます。インストーラーの画面を一通り見たいので「Only show new options」のチェックを外してから [Next >] ボタンをクリックします。
「Select Components」画面が表示されます。「Git LFS(Large File Support)」だけチェックした状態で [Next >]ボタンをクリックします。
「Choosing the default editor used by Git」画面が表示されます。「Use Vim (the ubiquitous text editor) as Git's default editor」が選択された状態で [Next >]ボタンをクリックします。
「Adjusting the name of the initial branch in new repositories」画面が表示されます。「Let Git decide」が選択されていることを確認後、[Next >]ボタンをクリックします。
「Adjusting your PATH environment」画面が表示されます。中央の「Git from the command line and also from 3rd-party software」が選択されていることを確認後、[Next >]ボタンをクリックします。
「Choosing HTTPS transport backend」画面が表示されます。「Use the OpenSSL library」が選択されていることを確認後、[Next >]ボタンをクリックします。
「Configuring the line ending conversions」画面が表示されます。一番上の「Checkout Windows-style, commit Unix-style line endings」が選択されていることを確認した後、[Next >]ボタンをクリックします。
「Configuring the terminal emulator to use with Git Bash」画面が表示されます。「Use Windows'default console window」が選択されていることを確認した後、[Next >]ボタンをクリックします。
「Choose the default behavior of
git pull
」画面が表示されます。「Default (fast-forward or merge)」が選択されていることを確認した後、[Next >]ボタンをクリックします。「Choose a credential helper」画面が表示されます。「None」が選択されていることを確認した後、[Next >]ボタンをクリックします。
「Configuring extra options」画面が表示されます。「Enable file system caching」だけがチェックされていることを確認した後、[Next >]ボタンをクリックします。
「Configuring experimental options」画面が表示されます。何もチェックせずに [Install]ボタンをクリックします。
インストールが完了すると「Completing the Git Setup Wizard」のメッセージが表示された画面が表示されます。中央の「View Release Notes」のチェックを外した後、[Next >]ボタンをクリックしてインストーラーを終了します。
コマンドプロンプトを起動して
git --version
を実行し、git のバージョンがgit version 2.30.0.windows.2
になっていることを確認します。特に問題はないようですので、2.30.0.2 で作業を進めたいと思います。