Skip to content

Commit d3a6684

Browse files
authored
Merge pull request #100 from domaframework/docs/claude
Add CLAUDE.md for Claude Code guidance
2 parents 984dd51 + d4bccc8 commit d3a6684

File tree

1 file changed

+113
-0
lines changed

1 file changed

+113
-0
lines changed

CLAUDE.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Overview
6+
7+
The Doma Compile Plugin is a Gradle plugin that allows annotation processors to read Doma resources at compile-time. It supports both Java and Kotlin and is part of the Doma framework ecosystem.
8+
9+
## Common Commands
10+
11+
### Building the Plugin
12+
```bash
13+
./gradlew build
14+
```
15+
16+
### Running Tests
17+
The plugin has three test suites that must be run in sequence:
18+
```bash
19+
# Build the plugin first
20+
./gradlew build
21+
22+
# Test with Java
23+
cd compile-java-test && ./gradlew build && cd ..
24+
25+
# Test with Kotlin
26+
cd compile-kotlin-test && ./gradlew build && cd ..
27+
28+
# Test with mixed Java/Kotlin
29+
cd compile-mix-test && ./gradlew build && cd ..
30+
```
31+
32+
### Code Formatting
33+
```bash
34+
# Apply code formatting (Google Java Format)
35+
./gradlew spotlessApply
36+
```
37+
38+
### Running a Single Test
39+
```bash
40+
# In any test directory (compile-java-test, compile-kotlin-test, or compile-mix-test)
41+
./gradlew test --tests "example.GenerationTest"
42+
```
43+
44+
### Publishing (for maintainers)
45+
```bash
46+
# Release a new version (from master branch only)
47+
./gradlew release
48+
49+
# Publish to Gradle Plugin Portal (handled by CI for non-SNAPSHOT versions)
50+
./gradlew publishPlugins -Pgradle.publish.key=<key> -Pgradle.publish.secret=<secret>
51+
```
52+
53+
## Architecture
54+
55+
### Project Structure
56+
- **compile/**: Main plugin implementation
57+
- `CompilePlugin.java`: Entry point that applies configurations
58+
- `ConfigureJava.java`: Configures Java compilation to include resource directories in sourcepath
59+
- `ConfigureKotlin.groovy`: Configures Kotlin/KAPT to include resource directories
60+
61+
- **Test Projects**: Three separate Gradle projects for testing different scenarios
62+
- `compile-java-test/`: Tests plugin with pure Java
63+
- `compile-kotlin-test/`: Tests plugin with pure Kotlin
64+
- `compile-mix-test/`: Tests plugin with mixed Java/Kotlin
65+
66+
### How the Plugin Works
67+
The plugin modifies the compilation classpath to allow Doma's annotation processor to read SQL resource files during compile-time. It:
68+
69+
1. Adds resource directories to the Java compiler's sourcepath
70+
2. Adds the `-parameters` flag to preserve parameter names
71+
3. For Kotlin, configures KAPT with the same settings
72+
73+
This is equivalent to manually configuring:
74+
```kotlin
75+
compileJava {
76+
options.sourcepath = files(sourceSets.main.resources.srcDirs)
77+
options.compilerArgs.add("-parameters")
78+
}
79+
80+
kapt {
81+
javacOptions {
82+
option("--source-path", resourceDirs.join(File.pathSeparator))
83+
option("-parameters")
84+
}
85+
}
86+
```
87+
88+
### Resource File Convention
89+
Doma SQL resources follow a specific directory structure:
90+
- Location: `src/main/resources/META-INF/<package>/<DaoName>/`
91+
- SQL files: `<methodName>.sql` (e.g., `selectById.sql`)
92+
- Script files: `<methodName>.script` (e.g., `create.script`)
93+
94+
### Dependencies and Versions
95+
- Java: Requires Java 17 or later
96+
- Gradle: Uses Gradle wrapper
97+
- Doma: Compatible with Doma 3.8 or later
98+
- Testing: JUnit 5 (managed via BOM)
99+
100+
### CI/CD Pipeline
101+
GitHub Actions workflow (`.github/workflows/ci.yml`):
102+
1. Triggers on push/PR to master branch
103+
2. Uses JDK 21 on Ubuntu
104+
3. Builds plugin, then tests all three scenarios
105+
4. Auto-publishes non-SNAPSHOT versions to Gradle Plugin Portal
106+
107+
### Plugin Configuration
108+
The plugin is published as `org.domaframework.doma.compile` and can be applied:
109+
```kotlin
110+
plugins {
111+
id("org.domaframework.doma.compile") version "4.x.x"
112+
}
113+
```

0 commit comments

Comments
 (0)