|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Doma CodeGen Plugin is a Gradle plugin that generates Java, Kotlin, and SQL files from database schemas. It's part of the Doma framework ecosystem and supports Doma 3. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Build entire project with code formatting |
| 13 | +./gradlew spotlessApply build |
| 14 | + |
| 15 | +# Build only the plugin module |
| 16 | +./gradlew :codegen:build |
| 17 | + |
| 18 | +# Clean build |
| 19 | +./gradlew clean build |
| 20 | +``` |
| 21 | + |
| 22 | +## Testing Commands |
| 23 | + |
| 24 | +```bash |
| 25 | +# Run all tests |
| 26 | +./gradlew test |
| 27 | + |
| 28 | +# Run specific module tests |
| 29 | +./gradlew :codegen:test |
| 30 | +./gradlew :codegen-test:test |
| 31 | + |
| 32 | +# Test code generation (from codegen-test directory) |
| 33 | +cd codegen-test |
| 34 | +./gradlew domaCodeGenJavaAll build |
| 35 | +./gradlew domaCodeGenKotlinAll build |
| 36 | +``` |
| 37 | + |
| 38 | +## Code Quality |
| 39 | + |
| 40 | +```bash |
| 41 | +# Apply code formatting (required before commits) |
| 42 | +./gradlew spotlessApply |
| 43 | + |
| 44 | +# Check code formatting |
| 45 | +./gradlew spotlessCheck |
| 46 | +``` |
| 47 | + |
| 48 | +## Architecture Overview |
| 49 | + |
| 50 | +### Multi-Module Structure |
| 51 | +- **codegen**: Main plugin implementation |
| 52 | + - Plugin entry point: `CodeGenPlugin.java` |
| 53 | + - Tasks defined in `org.seasar.doma.gradle.codegen.task` package |
| 54 | + - Code generators in `org.seasar.doma.gradle.codegen.generator` package |
| 55 | + - Database dialects in `org.seasar.doma.gradle.codegen.dialect` package |
| 56 | + |
| 57 | +- **codegen-test**: Integration test project demonstrating plugin usage |
| 58 | + |
| 59 | +### Key Components |
| 60 | + |
| 61 | +1. **Code Generators**: Transform database metadata into Java/Kotlin code using FreeMarker templates |
| 62 | + - `JavaGenerator`: Generates Java entities and DAOs |
| 63 | + - `KotlinGenerator`: Generates Kotlin entities and DAOs |
| 64 | + - `SqlGenerator`: Generates SQL template files |
| 65 | + |
| 66 | +2. **Database Dialects**: Database-specific implementations for metadata extraction |
| 67 | + - Supports: H2, MySQL, Oracle, PostgreSQL, SQL Server, DB2, HSQLDB |
| 68 | + |
| 69 | +3. **Gradle Tasks**: Plugin provides tasks prefixed with `domaCodeGen` |
| 70 | + - Pattern: `domaCodeGen{Java|Kotlin|Sql}{EntityName|All}` |
| 71 | + |
| 72 | +4. **Template System**: FreeMarker templates in `/codegen/src/main/resources/` |
| 73 | + - Customizable via `templateDir` configuration |
| 74 | + |
| 75 | +### Development Notes |
| 76 | + |
| 77 | +- Minimum Java version: 17 |
| 78 | +- Uses Gradle Kotlin DSL for build configuration |
| 79 | +- JUnit 5 for testing |
| 80 | +- Google Java Format for code style (enforced via Spotless) |
| 81 | +- Plugin ID: `org.domaframework.doma.codegen` |
| 82 | +- Current version: Check `gradle.properties` |
| 83 | + |
| 84 | +### Database Connection |
| 85 | + |
| 86 | +The plugin connects to databases to read metadata. Configure in build.gradle: |
| 87 | +```kotlin |
| 88 | +domaCodeGen { |
| 89 | + url = "jdbc:h2:mem:example" |
| 90 | + user = "sa" |
| 91 | + password = "" |
| 92 | +} |
| 93 | +``` |
0 commit comments