|
| 1 | +--- |
| 2 | +mode: 'agent' |
| 3 | +tools: ['changes', 'codebase', 'editFiles', 'findTestFiles', 'problems', 'runCommands', 'runTests', 'search', 'searchResults', 'terminalLastCommand', 'testFailure', 'usages'] |
| 4 | +description: 'Create Spring Boot Kotlin project skeleton' |
| 5 | +--- |
| 6 | + |
| 7 | +# Create Spring Boot Kotlin project prompt |
| 8 | + |
| 9 | +- Please make sure you have the following software installed on your system: |
| 10 | + |
| 11 | + - Java 21 |
| 12 | + - Docker |
| 13 | + - Docker Compose |
| 14 | + |
| 15 | +- If you need to custom the project name, please change the `artifactId` and the `packageName` in [download-spring-boot-project-template](./create-spring-boot-kotlin-project.prompt.md#download-spring-boot-project-template) |
| 16 | + |
| 17 | +- If you need to update the Spring Boot version, please change the `bootVersion` in [download-spring-boot-project-template](./create-spring-boot-kotlin-project.prompt.md#download-spring-boot-project-template) |
| 18 | + |
| 19 | +## Check Java version |
| 20 | + |
| 21 | +- Run following command in terminal and check the version of Java |
| 22 | + |
| 23 | +```shell |
| 24 | +java -version |
| 25 | +``` |
| 26 | + |
| 27 | +## Download Spring Boot project template |
| 28 | + |
| 29 | +- Run following command in terminal to download a Spring Boot project template |
| 30 | + |
| 31 | +```shell |
| 32 | +curl https://start.spring.io/starter.zip \ |
| 33 | + -d artifactId=demo \ |
| 34 | + -d bootVersion=3.4.5 \ |
| 35 | + -d dependencies=configuration-processor,webflux,data-r2dbc,postgresql,data-redis-reactive,data-mongodb-reactive,validation,cache,testcontainers \ |
| 36 | + -d javaVersion=21 \ |
| 37 | + -d language=kotlin \ |
| 38 | + -d packageName=com.example \ |
| 39 | + -d packaging=jar \ |
| 40 | + -d type=gradle-project-kotlin \ |
| 41 | + -o starter.zip |
| 42 | +``` |
| 43 | + |
| 44 | +## Unzip the downloaded file |
| 45 | + |
| 46 | +- Run following command in terminal to unzip the downloaded file |
| 47 | + |
| 48 | +```shell |
| 49 | +unzip starter.zip -d . |
| 50 | +``` |
| 51 | + |
| 52 | +## Remove the downloaded zip file |
| 53 | + |
| 54 | +- Run following command in terminal to delete the downloaded zip file |
| 55 | + |
| 56 | +```shell |
| 57 | +rm -f starter.zip |
| 58 | +``` |
| 59 | + |
| 60 | +## Add additional dependencies |
| 61 | + |
| 62 | +- Insert `springdoc-openapi-starter-webmvc-ui` and `archunit-junit5` dependency into `build.gradle.kts` file |
| 63 | + |
| 64 | +```gradle.kts |
| 65 | +dependencies { |
| 66 | + implementation("org.springdoc:springdoc-openapi-starter-webflux-ui:2.8.6") |
| 67 | + testImplementation("com.tngtech.archunit:archunit-junit5:1.2.1") |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +- Insert SpringDoc configurations into `application.properties` file |
| 72 | + |
| 73 | +```properties |
| 74 | +# SpringDoc configurations |
| 75 | +springdoc.swagger-ui.doc-expansion=none |
| 76 | +springdoc.swagger-ui.operations-sorter=alpha |
| 77 | +springdoc.swagger-ui.tags-sorter=alpha |
| 78 | +``` |
| 79 | + |
| 80 | +- Insert Redis configurations into `application.properties` file |
| 81 | + |
| 82 | +```properties |
| 83 | +# Redis configurations |
| 84 | +spring.data.redis.host=localhost |
| 85 | +spring.data.redis.port=6379 |
| 86 | +spring.data.redis.password=rootroot |
| 87 | +``` |
| 88 | + |
| 89 | +- Insert R2DBC configurations into `application.properties` file |
| 90 | + |
| 91 | +```properties |
| 92 | +# R2DBC configurations |
| 93 | +spring.r2dbc.url=r2dbc:postgresql://localhost:5432/postgres |
| 94 | +spring.r2dbc.username=postgres |
| 95 | +spring.r2dbc.password=rootroot |
| 96 | + |
| 97 | +spring.sql.init.mode=always |
| 98 | +spring.sql.init.platform=postgres |
| 99 | +spring.sql.init.continue-on-error=true |
| 100 | +``` |
| 101 | + |
| 102 | +- Insert MongoDB configurations into `application.properties` file |
| 103 | + |
| 104 | +```properties |
| 105 | +# MongoDB configurations |
| 106 | +spring.data.mongodb.host=localhost |
| 107 | +spring.data.mongodb.port=27017 |
| 108 | +spring.data.mongodb.authentication-database=admin |
| 109 | +spring.data.mongodb.username=root |
| 110 | +spring.data.mongodb.password=rootroot |
| 111 | +spring.data.mongodb.database=test |
| 112 | +``` |
| 113 | + |
| 114 | +- Create `docker-compose.yaml` at project root and add following services: `redis:6`, `postgresql:17` and `mongo:8`. |
| 115 | + |
| 116 | + - redis service should have |
| 117 | + - password `rootroot` |
| 118 | + - mapping port 6379 to 6379 |
| 119 | + - mounting volume `./redis_data` to `/data` |
| 120 | + - postgresql service should have |
| 121 | + - password `rootroot` |
| 122 | + - mapping port 5432 to 5432 |
| 123 | + - mounting volume `./postgres_data` to `/var/lib/postgresql/data` |
| 124 | + - mongo service should have |
| 125 | + - initdb root username `root` |
| 126 | + - initdb root password `rootroot` |
| 127 | + - mapping port 27017 to 27017 |
| 128 | + - mounting volume `./mongo_data` to `/data/db` |
| 129 | + |
| 130 | +- Insert `redis_data`, `postgres_data` and `mongo_data` directories in `.gitignore` file |
| 131 | + |
| 132 | +- Run gradle clean test command to check if the project is working |
| 133 | + |
| 134 | +```shell |
| 135 | +./graldew clean test |
| 136 | +``` |
| 137 | + |
| 138 | +- (Optional) `docker-compose up -d` to start the services, `./graldew spring-boot:run` to run the Spring Boot project, `docker-compose rm -sf` to stop the services. |
| 139 | + |
| 140 | +Let's do this step by step. |
0 commit comments