Springboot1-Create Multi-Module Project

·

2 min read

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

  1. Create Springboot Project

  2. Create new module ( I called it module1)

  1. In the settings.gradle.kts (include the sub module using below syntax
include("module1")

  1. 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

  1. Remove and clear unnecessary content

    1. Delete below files in sub module

      1. .gitignore

      2. gradlew

      3. gradlew.bat

      4. settings.gradle.kts

    2. Clear the content in build.gradle.kts

  2. Reload all gradle project in gradle plugin in intellij

  3. Try to run ./gradlew :module1:bootRun and hope everything is okay:)

Remarks

  1. Delete all the .gradle, .idea files and invalidate cache if you encounter any reload problem in intellij and it works for terminal