본문 바로가기

Backend/Spring

Spring Boot Gradle Multi Modules 초간단

Spring Initializr에서 프로젝트를 생성합니다.

그리고 저는 주로 사용하지 않을 src 폴더를 삭제합니다.

build.gradle을 먼저 작성해볼게요.

build.gradle

buildscript {
  ext {
    springBootVersion = '2.6.3'
    dependencyManagementVersion = '1.0.11.RELEASE'
  }

  repositories {
    mavenCentral()
  }

  dependencies {
    dependencies {
      classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
      classpath "io.spring.gradle:dependency-management-plugin:${dependencyManagementVersion}"
    }
  }
}


allprojects {
  group = 'com.example'
  version = '1.0.0'
}

subprojects {
  apply plugin: 'java'
  apply plugin: 'idea'
  apply plugin: 'org.springframework.boot'
  apply plugin: 'io.spring.dependency-management'

  sourceCompatibility = '11'

  configurations {
    compileOnly {
      extendsFrom annotationProcessor
    }
  }

  repositories {
    mavenCentral()
  }

  dependencies {
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
  }

  tasks.named('test') {
    useJUnitPlatform()
  }
}

project(':sample-api') {
  dependencies {
    implementation project(':sample-domain')
  }
}

project(':sample-batch') {
  dependencies {
    implementation project(':sample-domain')
  }
}

project(':sample-domain') {

}

 

settings.gradle

rootProject.name = 'sample'

include 'sample-api'
include 'sample-batch'
include 'sample-domain'

 

서브프로젝트는 src 폴더와 build.gradle 제외하고 필요한 것 빼고 필요 없습니다.

이렇게 설정하면 기본적으로 멀티 프로젝트 세팅은 완료된거에요.