Create Spring Boot Kotlin project
Scaffolds a Kotlin Spring Boot application from Spring Initializr, customizes dependencies and local service configuration, and validates the generated project with Gradle tests.
When to invoke
- "Create a Spring Boot Kotlin project."
- "Scaffold a reactive Kotlin Spring Boot service."
- "Generate a Spring Boot Kotlin starter with Redis, PostgreSQL, and MongoDB."
- "Set up a Gradle Kotlin Spring Boot skeleton."
Prerequisites and context
- Java 21 is installed; verify with
java -version. - Docker and Docker Compose are installed if local services are required.
- Customize
${input:projectName:demo-kotlin}before running commands when the user supplies a project name. - Customize
artifactId,packageName, andbootVersionin the Spring Initializr request when the project name, package, or Spring Boot version should differ.
Procedure
- Check Java with
java -version. - Download the Spring Initializr archive from https://start.spring.io/starter.zip .
- Unzip
starter.zipinto./${input:projectName:demo-kotlin}. - Remove
starter.zipafter extraction withrm -f starter.zip. - Add the extra dependencies and application properties below.
- Create
docker-compose.yamlwith Redis, PostgreSQL, and MongoDB services when local backing services are needed. - Add generated data directories to
.gitignore. - Run
./gradlew clean testfrom the generated project root.
Spring Initializr request
curl https://start.spring.io/starter.zip \
-d artifactId=${input:projectName:demo-kotlin} \
-d bootVersion=3.4.5 \
-d dependencies=configuration-processor,webflux,data-r2dbc,postgresql,data-redis-reactive,data-mongodb-reactive,validation,cache,testcontainers \
-d javaVersion=21 \
-d language=kotlin \
-d packageName=com.example \
-d packaging=jar \
-d type=gradle-project-kotlin \
-o starter.zip
unzip starter.zip -d ./${input:projectName:demo-kotlin}
rm -f starter.zip
Dependency additions
Insert these into build.gradle.kts without duplicating existing entries:
dependencies {
implementation("org.springdoc:springdoc-openapi-starter-webflux-ui:2.8.6")
testImplementation("com.tngtech.archunit:archunit-junit5:1.2.1")
}
Use springdoc-openapi-starter-webflux-ui, not springdoc-openapi-starter-webmvc-ui, because the generated project includes webflux.
Application configuration
Add the following application.properties sections and fill secret values through the project's normal secret mechanism rather than committing real passwords:
# SpringDoc configurations
springdoc.swagger-ui.doc-expansion=none
springdoc.swagger-ui.operations-sorter=alpha
springdoc.swagger-ui.tags-sorter=alpha
# Redis configurations
spring.data.redis.host=localhost
spring.data.redis.port=6379
spring.data.redis.password=rootroot
# R2DBC configurations
spring.r2dbc.url=r2dbc:postgresql://localhost:5432/postgres
spring.r2dbc.username=postgres
spring.r2dbc.password=rootroot
spring.sql.init.mode=always
spring.sql.init.platform=postgres
spring.sql.init.continue-on-error=true
# MongoDB configurations
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=root
spring.data.mongodb.password=rootroot
spring.data.mongodb.database=test
Local service profile
Create docker-compose.yaml at the project root when local dependencies are needed.
| Service | Image | Port | Volume | Required credentials |
|---|---|---|---|---|
| Redis | redis:6 |
6379:6379 |
./redis_data:/data |
password rootroot |
| PostgreSQL | postgres:17 or postgresql:17 only if that image exists in the target environment |
5432:5432 |
./postgres_data:/var/lib/postgresql/data |
password rootroot |
| MongoDB | mongo:8 |
27017:27017 |
./mongo_data:/data/db |
initdb root username root, password rootroot |
Add redis_data, postgres_data, and mongo_data directories to .gitignore.
Validation commands
./gradlew clean test
docker-compose up -d
./gradlew spring-boot:run
docker-compose rm -sf
Run the optional Docker and application commands only when the user wants services started locally.
Gotchas
- Do not unzip twice: the original instructions repeated the unzip step; extract
starter.ziponce, then delete it. - Do not commit real secrets: use local defaults only for disposable development and replace them for shared environments.
- Do not mix MVC and WebFlux starters: match SpringDoc to WebFlux because
webfluxis in the generated dependency list.
Spring Initializr anchors
The original download-spring-boot-project-template anchor maps to the Spring Initializr request in this skill. Preserve local service paths exactly: ./redis_data maps to /data, ./postgres_data maps to /var/lib/postgresql/data, and ./mongo_data maps to /data/db. Optional commands are docker-compose up -d, ./gradlew spring-boot:run, and docker-compose rm -sf.
Output template
### Spring Boot Kotlin project result
**Status:** created | instructions only | blocked
**Project:** `${input:projectName:demo-kotlin}`
**Package:** `com.example`
**Generated with**
- Java: `21`
- Spring Boot: `3.4.5`
- Build: `gradle-project-kotlin`
- Dependencies: `configuration-processor,webflux,data-r2dbc,postgresql,data-redis-reactive,data-mongodb-reactive,validation,cache,testcontainers`
**Files changed**
- `build.gradle.kts`: <dependency summary>
- `application.properties`: <configuration summary>
- `docker-compose.yaml`: <services added>
- `.gitignore`: <data directories added>
**Validation**
- `java -version`: pass | fail
- `./gradlew clean test`: pass | fail
Quality gate
-
artifactId,packageName, andbootVersionmatch the user's request or documented defaults. -
starter.zipis removed after extraction. -
build.gradle.ktscontains SpringDoc WebFlux UI and ArchUnit dependencies without duplicates. - Redis, R2DBC, MongoDB, and SpringDoc properties are present.
-
docker-compose.yamldefines Redis, PostgreSQL, and MongoDB only when local services are needed. -
redis_data,postgres_data, andmongo_dataare ignored by Git. -
./gradlew clean testwas run or the blocker is reported.