build.gradle 설명
1. plugins 블록 : 미리 구성해놓은 task들의 그룹
1) group : 프로젝트 정보
2) version : 프로젝트 버전
3) sourceCompatibility : JDK 버전 소스 호환성
plugins {
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'org.asciidoctor.convert' version '1.5.8'
id 'java'
}
group = 'templateClone'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
2. configurations 블록 : 아티팩트 및 해당 종속성 그룹을 표기
configurations {
asciidoctorExtensions // : API문서화를 위해 추가
compileOnly {
extendsFrom annotationProcessor
}
}
3. repositories블록 : 저장소 설정
repositories {
mavenLocal() // maven 로컬 저장소
mavenCentral() // maven 중앙 저장소
maven { url "http://repo.company.com/maven" } // maven 원격 저장소
}
4. ext 블록 : build.gradle 내에서 쓸 전역변수를 선언하는 키워드
ext {
set('snippetsDir', file("build/generated-snippets"))
}
5. dependencies 블록 : Java의 의존성 관리를 위한 구성
1) implementation : 전 범위에 걸쳐서 적용
2) testplementation : 테스트 시에만 적용
3) runtimeOnly : 실행 시점에만 적용
4) compileOnly : 컴파일 시점에만 적용
5) annotationProcessor : Querydsl JPA 프로젝트 내에서 @Entity 애너테이션 선언한 클래스를 탐색하여,
Q클래스를 생성하게 해주는 라이브러리.
* 생성된 Q클래스는 자바 언어의 정적 코드 특성을 통해 안전한 쿼리문으로 작성가능
6) debugImplemantation : 디버그 모드에서만 적용
7) providedCompile : 컴파일시에는 필요하나, 배포시에는 제외될 dependencies 설정
* 단, war plugin이 설정된 경우에만 사용가능
8) providedRuntime : 런타임시에는 필요하나, 실행환경에서는 제공될 dependencies 설정
* 단, war plugin이 설정된 경우에만 사용가능
9) androidTestImplementation : 안드로이드 테스트 수행시만 적용
* 기타 다른 의존성 관계 : 공식문서
6. tasks 블록
: 빌드가 실행하는 최소 단위의 작업
: tasks.named('이름') 으로 작업 이름을 정할 수 있다
자주쓰는 build.gradle 기본 설정
plugins {
id 'org.springframework.boot' version '2.7.5'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'org.asciidoctor.convert' version '1.5.8'
id 'java'
}
group = 'templateClone'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
asciidoctorExtensions // : API문서화를 위해 추가
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
ext {
set('snippetsDir', file("build/generated-snippets"))
}
dependencies {
// 라이브러리 부분
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.8.0' // P6 : SQL log로그와 필드변수 매칭용 확장
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-aop' // AspectJ : 자바 애너테이션을 이용해 aspect를 선언하는 라이브러리
implementation group: 'com.google.code.gson', name: 'gson' // gson
implementation 'io.jsonwebtoken:jjwt-api:0.11.5' // jjwt는 JWT 토큰 생성 및 JWT 토큰 파싱, 검증을 해주는 라이브러리
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'mysql:mysql-connector-java' // MySQL용 확장
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
// DB 부분
// runtimeOnly 'com.h2database:h2' // h2 인메모리 사용시 활성화
}
tasks.named('test') {
outputs.dir snippetsDir
useJUnitPlatform()
}
tasks.named('asciidoctor') {
// configurations "asciidoctorExtensions"
inputs.dir snippetsDir
dependsOn test
}
task copyDocument(type: Copy) {
dependsOn asciidoctor
from file("${asciidoctor.outputDir}")
into file("src/main/resources/static/docs")
}
build {
dependsOn copyDocument
}
bootJar {
dependsOn copyDocument
from ("${asciidoctor.outputDir}") {
into 'static/docs'
}
}
링크
나의 GitHub 링크 : https://github.com/PNUHCT/TemplateReview.git
참고 자료 : https://velog.io/@7lo9ve3/gradle
'Java & Spring > 프로젝트 기본 설정' 카테고리의 다른 글
[SpringBoot] 프로젝트 워크 플로우 (0) | 2022.11.03 |
---|---|
[SpringBoot] application.yml 설정 저장 (0) | 2022.11.02 |
[SpringBoot] Advice (진행중) (0) | 2022.10.20 |
[SpringBoot] Exception (진행중) (0) | 2022.10.20 |
[SpringBoot] Repository (0) | 2022.10.20 |