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