SpringBoot 프로젝트 구조 정하기 - group, artifactId, Multi-module

노현아·2024년 4월 17일

group

group은 프로젝트를 식별하는 고유한 식별자로, 일반적으로 도메인 이름을 반대로 작성하여 사용한다. 이때 Java의 패키지 이름 규칙을 따른다.

ex. com.example.myproject
ex. com.example.my.project1 / com.example.my.project2

artifactId

artifactId는 프로젝트의 이름이다. 소문자로만 작성한다.

group와 artifactId

group과 artifactId는 함께 프로젝트를 식별하는 데 사용된다.
예를 들어, com.example:myapp에서 com.example은 groupId이고, myproject artifactId다.

com.example:myproject

  • com.example이라는 그룹의 myproject 프로젝트를 의미한다.

SpringBoot 프로젝트 구조

myproject
│   build.gradle
└───src
    └───main
    │   └───java
    │   │   └───com
    │   │       └───example
    │   │           └───myproject
    │   │               │   MyProjectApplication.java
    │   │               └───controller
    │   │               │   └───HelloController.java
    │   │               └───service
    │   │               │   └───HelloService.java
    │   │               └───repository
    │   │               │   └───HelloRepository.java
    │   └───resources
    │       │   application.properties
    └───test
        └───java
            └───com
                └───example
                    └───myproject
                        │   MyProjectApplicationTests.java

Multi-module

프로젝트 구조

멀티 모듈 프로젝트는 여러 개의 서브 모듈로 구성되며, 각 모듈은 독립적인 빌드 단위를 가진다.

my-multi-module-project
│   settings.gradle
│   build.gradle
└───module1
│   │   build.gradle
└───module2
    │   build.gradle

최상위 settings.gradle, build.gradle 파일 설정

  • 최상위 build.gradle 파일과 settings.gradle 파일을 먼저 설정한다.

settings.gradle

rootProject.name = 'my-multi-module-project'
include 'module1', 'module2'

build.gradle


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

subprojects {
    apply plugin: 'java'

    repositories {
        mavenCentral()
    }

    dependencies {
        testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
        testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
    }

    test {
        useJUnitPlatform()
    }
}

하위 모듈의 build.gradle 파일 설정

module1/build.gradle


//
apply plugin: 'java'

dependencies {
    implementation project(':module2')
}

jar {
    archiveBaseName.set('module1')
}

module2/build.gradle



apply plugin: 'java'

jar {
    archiveBaseName.set('module2')
}

각 모듈 별로, archiveBaseName에 의해 다음과 같이 group과 artifactId가 설정된다:

// module1:
group: com.example
artifactId: module1
version: 1.0.0

//module2:
group: com.example
artifactId: module2
version: 1.0.0
profile
성실함과 끊임없는 학습을 통해 성장하는 개발자 지망생입니다. 새로운 도전과 배움을 즐기며 더 나은 코드를 꿈꿉니다.

0개의 댓글