Code Generation
Overview
ElastiCORE automatically generates complete Spring Boot application code based on DSL (model/*.yml) definitions.
Code Generation Command
./gradlew elcore
This command parses the DSL definitions and automatically generates the following code:
- Entity: JPA entity classes
- DTO: Data transfer objects
- Repository: Spring Data JPA repositories
- Service: Service layer
- Controller: REST API controllers (when
@exposeis used) - SearchDTO: Search condition DTOs (when
@expose,@service, or@searchableis used) - Q classes: Specification-based dynamic queries
- Port Interface: External system communication interfaces
- Test Code: JUnit 5-based unit tests (when
testCode.enabled: trueis configured)
Generation Process
1. DSL Parsing
Read blueprint/{domain}/*.yml files
↓
2. Model Validation
Grammar validation, referential integrity checks
↓
3. Code Generation
Generate Java source using the template engine
↓
4. File Output
Write files to package paths based on namespace configuration
Generation Modes
The code generated depends on the mode setting in env.yml:
| Mode | Generated Items |
|---|---|
jpa | Entity, DTO, Repository, Service, Controller |
mongo | MongoDB Document, Repository, Service |
uml | Mermaid diagrams (deprecated) |
px | PX platform integration code |
config:
mode: jpa # JPA mode
# mode: jpa,uml # Multiple modes supported
Regeneration Rules
One-time Generation (Default)
If a generated file contains a marker comment, it will not be regenerated:
/*
* No longer managed by ElastiCORE. You may modify as needed,
* but retain the marker for traceability.
*/
Forced Regeneration
Delete the file and then run ./gradlew elcore to regenerate it.
tip
When regeneration is needed, make sure to back up existing files before deleting them. Custom code may be lost.
Next Steps
- Project Structure - Understand the generated file structure
- Modifying Generated Code - Guide on modifying generated code
- Customization - Customization using block comments