Springboot1-Create Multi-Module Project
The thought is like that. First, create a simple Koltin spring boot project in IntelliJ, and then organize it into a multi-module project.
Procedure
Create Springboot Project
Create new module ( I called it module1)
- In the settings.gradle.kts (include the sub module using below syntax
include("module1")
In the build.gradle.kts in root directory, copy the below code
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins{ id("org.springframework.boot") version "3.2.4" id("io.spring.dependency-management") version "1.1.4" kotlin("jvm") version "1.9.23" kotlin("plugin.spring") version "1.9.23" } subprojects{ // Apply the plugin declared before apply(plugin="org.springframework.boot") apply(plugin="io.spring.dependency-management") apply(plugin="org.jetbrains.kotlin.jvm") apply(plugin="org.jetbrains.kotlin.plugin.spring") group = "com.example" version = "0.0.1-SNAPSHOT" java { sourceCompatibility = JavaVersion.VERSION_17 } repositories { mavenCentral() } dependencies { implementation("org.springframework.boot:spring-boot-starter") implementation("org.jetbrains.kotlin:kotlin-reflect") testImplementation("org.springframework.boot:spring-boot-starter-test") } tasks.withType<KotlinCompile> { kotlinOptions { freeCompilerArgs += "-Xjsr305=strict" jvmTarget = "17" } } tasks.withType<Test> { useJUnitPlatform() } }
1: the plugin will not automatically apply in the subproject closure, so we need to apply it explicitly
Remove and clear unnecessary content
Delete below files in sub module
.gitignore
gradlew
gradlew.bat
settings.gradle.kts
Clear the content in build.gradle.kts
Reload all gradle project in gradle plugin in intellij
Try to run ./gradlew :module1:bootRun and hope everything is okay:)
Remarks
- Delete all the .gradle, .idea files and invalidate cache if you encounter any reload problem in intellij and it works for terminal