添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

[Spring][프로젝트] Gradle MultiModule 세팅

모두한 · 2021년 11월 30일
1

쇼핑몰프로젝트

목록 보기
1 / 3

Gradle MultiModule 세팅하기

그레이들 멀티모듈을 세팅하며 헷갈리고 어려웠던 부분을 정리합니다.

모듈간 참조 그림

누구든 상품을 판매할 수 있는 마켓컨셉의 웹애플리케이션

빌드 에러 발생

위 주제로 프로젝트를 하기로 결정하였습니다.
한개의 단일 애플리케이션으로 띄우기 보다는 애플리케이션의 사이즈를 고려하여 두 개의 모듈로 나누어 진행을 하기로 하였습니다.

모듈들간의 관계는 위 그림과 같습니다.
Root 모듈에서 모든 의존성을 관리합니다.
그리고 module-admin에서 필요한 객체들이 module-web과 같기에 해당 admin은 web을 참조합니다.

공통된 부분을 따로 또 모듈로 빼기보단 module-web에서 공통모듈을 관리하며 module-admin에서 참조하기로 결정했습니다.

그런데 Root 에서 빌드를 진행해보니

$ gradle build
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :bootJar FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootJar'.
> Error while evaluating property 'mainClass' of task ':bootJar'
   > Failed to calculate the value of task ':bootJar' property 'mainClass'.
      > Main class name has not been configured and it could not be resolved
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 5s
2 actionable tasks: 2 executed

위와 같은 에러가 발생하였습니다.

해당 에러는 main메서드가 없는 모듈을 빌드하려고 할 때 생기는 에러였습니다.

현재 애플리케이션을 실행하는 main메서드는 module-web 과 module-admin에만 존재하고

root 모듈에는 실제 main메서드가 존재하지 않습니다.

그래서 Root module의 build.gradl에 아래와 같은 구문을 작성해주니 해결되었습니다.

bootJar {
    enabled = false
jar {
    enabled = true

module-admin에서 module-web 참조

module-admin 에서 module-web의 클래스파일들을 참조하여 이용할 수 있어야 했기 때문에

Root module의 build.gradle에 아래와 같은 구문을 작성해주었습니다.

project(':module-admin') {
    dependencies {
        implementation project(':module-web')

공통 의존성 관리

Root 모듈의 build.gradle에 아래와 같은 구문을 작성해줍니다.
module-admin과 module-web에서 공통으로 필요한 의존성입니다.

subprojects {
    apply plugin: 'java'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'
    dependencies {
        developmentOnly 'org.springframework.boot:spring-boot-devtools'
        implementation 'org.springframework.boot:spring-boot-starter-web'
        implementation 'org.springframework.boot:spring-boot-starter-security'
        implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
        implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
        implementation 'com.h2database:h2:1.4.200'
        compileOnly 'org.projectlombok:lombok'
        annotationProcessor 'org.projectlombok:lombok'
        testImplementation 'org.springframework.boot:spring-boot-starter-test'
        testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
        testImplementation 'org.springframework.security:spring-security-test'
        implementation 'io.jsonwebtoken:jjwt:0.9.1'