Skip to main content

Configuration

Haft can be configured through command-line flags and configuration files.

Configuration Files

Haft supports two configuration files:

Config TypeFile NameLocationPurpose
Project Config.haft.yamlProject root directoryProject-specific settings
Global Configconfig.yaml~/.config/haft/User-wide defaults

Project Configuration (.haft.yaml)

Create a .haft.yaml file in your project root to configure project-specific settings:

version: "1"

project:
name: "my-app"
group: "com.example"
artifact: "my-app"
description: "My Spring Boot application"
package: "com.example.myapp"

spring:
version: "3.4.0"

java:
version: "21"

build:
tool: "maven" # maven, gradle, gradle-kotlin

architecture:
style: "layered" # layered, hexagonal, clean

database:
type: "postgresql" # postgresql, mysql, h2, etc.

generators:
dto:
style: "record" # record, class
tests:
enabled: true

Project Config Reference

KeyTypeDefaultDescription
versionstring"1"Config file version
project.namestring""Project name
project.groupstring""Maven group ID
project.artifactstring""Maven artifact ID
project.descriptionstring""Project description
project.packagestring""Base Java package
spring.versionstring"3.4.0"Spring Boot version
java.versionstring"21"Java version
build.toolstring"maven"Build tool (maven, gradle, gradle-kotlin)
architecture.stylestring"layered"Architecture style
database.typestring"postgresql"Database type
generators.dto.stylestring"record"DTO generation style
generators.tests.enabledbooltrueGenerate test files

Global Configuration (~/.config/haft/config.yaml)

Create a global config file to set user-wide defaults:

defaults:
java_version: "21"
build_tool: "maven"
architecture: "layered"
spring_boot: "3.4.0"

output:
colors: true
verbose: false

Global Config Reference

KeyTypeDefaultDescription
defaults.java_versionstring"21"Default Java version for new projects
defaults.build_toolstring"maven"Default build tool
defaults.architecturestring"layered"Default architecture style
defaults.spring_bootstring"3.4.0"Default Spring Boot version
output.colorsbooltrueEnable colored output
output.verboseboolfalseEnable verbose output

Command-Line Flags

Global Flags

Available for all commands:

FlagDescription
--verboseEnable verbose output for debugging
--no-colorDisable colored output
--helpShow help for any command
--versionShow version information

Example

haft --verbose init my-app
haft --no-color init

Default Values

When using the interactive wizard, these values are pre-selected:

Project Defaults

FieldDefault Value
Group IDcom.example
Version0.0.1-SNAPSHOT
Java Version21
Build Toolmaven
Packagingjar
Config Formatyaml

Generation Defaults

SettingDefault
Use LombokAuto-detect from build file
Use MapStructAuto-detect from build file
Use ValidationAuto-detect from build file

Overriding Defaults

Per-Command

haft init my-app --java 17 --build gradle

Non-Interactive Mode

Provide all required values via flags:

haft init my-app \
--group com.company \
--artifact my-service \
--java 21 \
--spring 3.4.0 \
--build maven \
--packaging jar \
--config yaml \
--deps web,jpa,lombok \
--no-interactive

Configuration Priority

Haft uses the following priority order (highest to lowest):

  1. Command-line flags - Always take precedence
  2. Project config (.haft.yaml) - Project-specific settings
  3. Global config (~/.config/haft/config.yaml) - User defaults
  4. Built-in defaults - Fallback values

Dependency Detection

When generating code, Haft reads your build file (pom.xml or build.gradle) to detect:

Lombok Detection

Maven - Looks for:

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

Gradle - Looks for:

compileOnly 'org.projectlombok:lombok'
// or
annotationProcessor 'org.projectlombok:lombok'

Effect: Generated entities use @Data, @Builder, etc.

MapStruct Detection

Maven - Looks for:

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</dependency>

Gradle - Looks for:

implementation 'org.mapstruct:mapstruct'

Effect: Generates mapper interfaces with @Mapper annotation.

Validation Detection

Maven - Looks for:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

Gradle - Looks for:

implementation 'org.springframework.boot:spring-boot-starter-validation'

Effect: Controllers use @Valid on request parameters.

Spring Data JPA Detection

Maven - Looks for:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

Gradle - Looks for:

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

Effect: Repositories extend JpaRepository.

CI/CD Configuration

For automated environments, always use --no-interactive:

# GitHub Actions example
- name: Generate project
run: |
haft init ${{ github.event.inputs.project_name }} \
--group ${{ github.event.inputs.group_id }} \
--java 21 \
--deps web,jpa,actuator \
--no-interactive

Shell Completion

Enable shell completion for better CLI experience:

# Bash
echo 'source <(haft completion bash)' >> ~/.bashrc

# Zsh
echo 'source <(haft completion zsh)' >> ~/.zshrc

# Fish
haft completion fish > ~/.config/fish/completions/haft.fish