1 minute read

구동 환경

  • Java 1.8
  • Gradle 6.1.1

프로젝트 구성

multi-project
├── gradle
├── multi-library
├── multi-api
└── multi-web
  • gradle: gradle wrapper 위치
  • multi-library: API, Web에서 공통으로 사용할 라이브러리 프로젝트
  • multi-api: API 서비스 프로젝트
  • multi-web: Web 서비스 프로젝트

프로젝트 생성

Root 프로젝트 생성

새 프로젝트를 만들고 Gradle Warpper를 프로젝트에 추가한다.

$ mkdir multi-project
$ cd multi-project
$ gradle init

Select type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4] 1

Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2] 1

Project name (default: multi-project):

> Task :init
Get more help with your project: https://guides.gradle.org/creating-new-gradle-builds

BUILD SUCCESSFUL
2 actionable tasks: 2 executed
  • Project name은 default로 진행한다.

build.gradle에 하위 프로젝트 설정 추가

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This is a general purpose Gradle build.
 * Learn how to create Gradle builds at https://guides.gradle.org/creating-new-gradle-builds
 */
subprojects {
    group = 'com.ddoong2.multi'

    repositories {
        mavenCentral()
    }
}
  • subprojects: 하위 프로젝트에 공통으로 구성될 설정

multi-library 하위 프로젝트 추가

$ mkdir multi-library
$ cd multi-library
$ touch build.gradle

multi-library/build.gradle 설정 추가

plugins {
    id 'java-library'
}

version = '1.0.0'
sourceCompatibility = '1.8'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
    compileOnly {
        extendsFrom annotationProcessor
    }
}

dependencies {
    compileOnly 'org.projectlombok:lombok:1.18.10'
    annotationProcessor 'org.projectlombok:lombok:1.18.10'
    implementation 'org.slf4j:slf4j-api:1.7.30'
    implementation 'ch.qos.logback:logback-core:1.2.3'
    implementation 'ch.qos.logback:logback-classic:1.2.3'
    testImplementation 'org.junit.jupiter:junit-jupiter:5.5.2'
    testImplementation 'org.assertj:assertj-core:3.13.2'
    testImplementation 'org.mockito:mockito-core:3.1.0'
    testImplementation 'org.mockito:mockito-junit-jupiter:3.2.4'
}

test {
    useJUnitPlatform()
}

settings.gradle 하위 프로젝트 추가

rootProject.name = 'multi-project'

include 'multi-library'

multi-api 하위 프로젝트 추가

$ mkdir multi-api
$ cd multi-api
$ touch build.gradle

multi-api/build.gradle 설정 추가

plugins {
    id 'org.springframework.boot' version '2.2.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

version = '1.0.0'
sourceCompatibility = '1.8'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
    compileOnly {
        extendsFrom annotationProcessor
    }
}

dependencies {
    implementation project(':multi-library')
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.h2database:h2'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

  • implementation project(':multi-library'): multi-library를 사용하게 추가한다.

settings.gradle 하위 프로젝트 추가

rootProject.name = 'multi-project'

include 'multi-library', 'multi-api'

multi-web 하위 프로젝트 추가

$ mkdir multi-web
$ cd multi-web
$ touch build.gradle

multi-web/build.gradle 설정 추가

plugins {
    id 'org.springframework.boot' version '2.2.4.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
}

version = '1.0.0'
sourceCompatibility = '1.8'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
    compileOnly {
        extendsFrom annotationProcessor
    }
}

dependencies {
    implementation project(':multi-library')
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'com.h2database:h2'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

  • implementation project(':multi-library'): multi-library를 사용하게 추가한다.

settings.gradle 하위 프로젝트 추가

rootProject.name = 'multi-project'

include 'multi-library', 'multi-api', 'multi-web'

참고

Leave a comment