.agents/skills/gradle-convention-plugin/SKILL.md
Gradleビルドロジックをconvention pluginとして共通化し、マルチモジュールプロジェクトでの設定重複を排除する場合に使用する。
npx skillsauth add ymkz/demo-monorepo gradle-convention-pluginInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
GradleのConvention Pluginを使用して、共通のビルド設定をプラグインとして切り出し、複数のサブプロジェクトで共有する。
gradle/
├── convention/
│ ├── build.gradle.kts
│ ├── settings.gradle.kts
│ └── src/main/kotlin/
│ ├── common-conventions.gradle.kts
│ ├── java-conventions.gradle.kts
│ └── spring-boot-conventions.gradle.kts
├── libs.versions.toml
settings.gradle.kts
gradle/convention/build.gradle.kts:
plugins {
`kotlin-dsl`
}
repositories {
mavenCentral()
}
dependencies {
implementation(libs.spotless)
}
gradle/convention/settings.gradle.kts:
dependencyResolutionManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
versionCatalogs {
create("libs") {
from(files("../libs.versions.toml"))
}
}
}
settings.gradle.kts:
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
rootProject.name = "demo"
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
}
includeBuild("gradle/convention")
include(":apps:core", ":apps:api")
gradle/convention/src/main/kotlin/common-conventions.gradle.kts:
plugins {
java
id("com.diffplug.spotless")
}
repositories {
mavenCentral()
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
group = "dev.ymkz.demo"
version = "1.0.0"
spotless {
java {
palantirJavaFormat()
}
kotlinGradle {
ktlint()
}
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.compilerArgs.addAll(
listOf("-Xlint:unchecked", "-Xlint:deprecation")
)
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.named("build") {
dependsOn("spotlessApply")
}
sourceSets {
create("intTest") {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
java {
setSrcDirs(listOf("src/intTest/java"))
}
resources {
setSrcDirs(listOf("src/intTest/resources"))
}
}
}
configurations {
named("intTestImplementation") {
extendsFrom(configurations.testImplementation.get())
}
named("intTestRuntimeOnly") {
extendsFrom(configurations.testRuntimeOnly.get())
}
}
tasks.register<Test>("intTest") {
useJUnitPlatform()
group = "verification"
description = "Runs the integration-test suite."
testClassesDirs = sourceSets["intTest"].output.classesDirs
classpath = sourceSets["intTest"].runtimeClasspath
}
tasks.named("check") {
dependsOn("intTest")
}
apps/api/build.gradle.kts:
plugins {
id("common-conventions")
alias(libs.plugins.spring.boot)
alias(libs.plugins.springdoc.openapi)
}
dependencies {
implementation(platform(libs.spring.boot.bom))
implementation(libs.bundles.api)
testImplementation(libs.bundles.unit.test)
intTestImplementation(libs.bundles.integration.test)
implementation(project(":apps:core"))
}
// java-conventions.gradle.kts
plugins {
id("common-conventions")
`java-library`
}
dependencies {
testImplementation(platform(libs.junit.bom))
testImplementation(libs.bundles.unit.test)
}
// spring-boot-conventions.gradle.kts
plugins {
id("java-conventions")
alias(libs.plugins.spring.boot)
}
dependencies {
implementation(platform(libs.spring.boot.bom))
implementation(libs.bundles.api)
}
// apps/api/build.gradle.kts
plugins {
id("spring-boot-conventions")
alias(libs.plugins.springdoc.openapi)
}
// src/main/kotlin/java-quality.gradle.kts
plugins {
checkstyle
jacoco
}
checkstyle {
toolVersion = "10.12.0"
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
}
jacoco {
toolVersion = "0.8.11"
}
tasks.jacocoTestReport {
reports {
xml.required.set(true)
html.required.set(true)
}
}
| プラグイン名 | 用途 |
|------------|------|
| common-conventions | 全プロジェクト共通の基本設定 |
| java-conventions | Javaプロジェクト向け設定 |
| spring-boot-conventions | Spring Bootプロジェクト向け設定 |
| library-conventions | ライブラリ公開向け設定 |
// ✅ 良い: プラグインに必要な依存のみをconventionに追加
// gradle/convention/build.gradle.kts
dependencies {
implementation(libs.spotless)
implementation(libs.spring.boot.gradle.plugin)
}
// ❌ 避ける: ライブラリ依存をここに含めない
// これらは各プロジェクトのbuild.gradle.ktsで定義
dependencies {
// implementation(libs.spring.boot.starter.web) // NG
}
// ✅ convention plugin内でもcatalogが使用可能
spotless {
java {
palantirJavaFormat()
}
}
// カスタムタスクでの使用
tasks.register("showVersions") {
doLast {
println("Spring Boot: ${libs.versions.spring.boot.get()}")
}
}
| 問題 | 原因 | 解決策 |
|------|------|--------|
| プラグインが見つからない | includeBuildされていない | rootのsettings.gradle.ktsを確認 |
| catalogが参照できない | conventionのsettings設定不足 | versionCatalogs設定を確認 |
| 変更が反映されない | ビルドキャッシュ | ./gradlew --stop後再実行 |
| IDEでエラー表示 | Gradle同期待ち | Gradleプロジェクトを再インポート |
// apps/api/build.gradle.kts
plugins {
java
id("com.diffplug.spotless") version "6.23.0"
}
java {
toolchain { languageVersion.set(JavaLanguageVersion.of(21)) }
}
spotless { java { palantirJavaFormat() } }
tasks.withType<Test> { useJUnitPlatform() }
// apps/core/build.gradle.kts(同じ設定の繰り返し)
plugins {
java
id("com.diffplug.spotless") version "6.23.0"
}
java {
toolchain { languageVersion.set(JavaLanguageVersion.of(21)) }
}
spotless { java { palantirJavaFormat() } }
tasks.withType<Test> { useJUnitPlatform() }
// gradle/convention/src/main/kotlin/common-conventions.gradle.kts
plugins {
java
id("com.diffplug.spotless")
}
java {
toolchain { languageVersion.set(JavaLanguageVersion.of(21)) }
}
spotless { java { palantirJavaFormat() } }
tasks.withType<Test> { useJUnitPlatform() }
// apps/api/build.gradle.kts
plugins {
id("common-conventions")
}
// apps/core/build.gradle.kts
plugins {
id("common-conventions")
}
tools
npm/pnpmベースのモノレポでWireitを使用してビルドパイプラインの依存関係を管理し、キャッシュと並列実行を活用する場合に使用する。
tools
このプロジェクトでは1リクエストあたりの全イベントを1つのJSONログに集約する「ワイドイベントロギング」を採用している。MDCとThreadLocalを組み合わせ、リクエスト処理のトレーサビリティ向上とパフォーマンス分析を実現する。
testing
単体テストとインテグレーションテストを使い分ける場合に使用する。テストピラミッドに基づき、テストの責務、実行速度、メンテナンスコストを考慮して適切なテスト戦略を選択する。
development
Spiceflow is a super simple, fast, and type-safe API and React Server Components framework for TypeScript. Works on Node.js, Bun, and Cloudflare Workers. Use this skill whenever working with spiceflow to get the latest docs and API reference.