본문 바로가기
개발의 기록/Etc..

IntelliJ에서 Gradle을 활용한 멀티프로젝트(multiproject)

by prographer J 2020. 2. 12.
728x90

 

프로젝트를 진행하다보면 특성별로 프로젝트를 나눠서 관리해야 하는 경우가 왕왕 생긴다.

예를들어 Frontend, Backend를 갖고 있는 서비스가 있다면 이 두곳에서 사용하는 공통 라이브러리를 이용하여 모델들을 관리해야 하는 경우가 생긴다. 

이럴경우 Gradle에서 멀티프로젝트를 생성하는 법을 기록에 남기고자 한다.

 

1. 프로젝트 설정

    File -> New Project -> Gradle -> Java

2. 각 설정정보를 입력한다.

3. Settings.gradle에 설정 값을 저장 한다.

rootProject.name = 'sample'
include 'common'
include 'frontend'
include 'backend'

 

4. 최상위 build.gradle 파일에 설정 값을 저장한다.

   설정시 allprojects와 subprojects를 이용하여 각 모듈(프로젝트)에 대해서 설정이 가능한다, allproject는 부모 모듈(프로젝트)까지 설정이 되는 것이고 subprojects는 그 하위모듈(프로젝트)에만 설정이 가능 하도록 하는 것인다.

 

* 참고: allprojects나 subprojects에는 plugins를 사용할 수 없어 apply plugin을 이용하여 플러그인을 설정해야 한다.

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

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

    group = 'com.example'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = '1.8'

    repositories {
        mavenCentral()
    }


    dependencies {
        testImplementation('org.springframework.boot:spring-boot-starter-test') {
            exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
        }
    }
}


project(':common') {
    bootJar {
        enabled = false
    }
    jar {
        enabled = true
    }
    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

        runtimeOnly 'com.h2database:h2'
        runtimeOnly 'org.postgresql:postgresql'
    }
}

project(':frontend') {
    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-web'
        implementation project(':common')
    }
}

project(':backend') {
    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-web'
        implementation project(':common')
    }
}

5. 마지막 최종 프로젝트 구조 화면

 

끝으로.. 열심히 쓴 글이 날라가 버려서 다시 작성했습니다... 이것저것 사족을 제외하고 필요한 내용만 작성 했습니다... 나중에 다시 쓰고싶은 생각이 들면... 다시 작성 할게요..ㅠㅠ

아..임시저장을 눌렀는데 어디갔지...

 

728x90

댓글