스크립트 개인 메모 -> jpa, querydsl....모두 적용까지
https://github.com/KimHyeongi/gradle-multi-module
root-project
- core
- api
workspaces에서 {root-project} 디렉토리 생성 후, 각 하위 디렉토리 생성.
settings.gradle 각 디렉토리에 생성.
root-project
rootProject.name = 'grissom-multi-module'
include 'core'
include 'api'
core
rootProject.name = 'multi-module-core'
api
rootProject.name = 'multi-module-api'
root-project디렉토리에서 gradle wrapper 생성하기 ( version 5.6.3 )
#> gradle wrapper --gradle-version 5.6.3
생성 확인.
각 모듈별 build.gradle 생성.( 통합 가능 - subproject task )
ex)
root:
plugins {
id "java"
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
}
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
group = 'com.tistory.eclipse4j'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
jcenter()
mavenCentral()
}
dependencies {
}
}
core :
주의) 기존 Gradle 관련 부분을 찾다보면 plugins에 "annotation-processor-plugin"가 추가된 경우가 있는데 넣지 말자..고생함.
plugins {
id "org.springframework.boot" version "2.2.0.RELEASE"
id "io.spring.dependency-management" version "1.0.8.RELEASE"
id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
id "io.franzbecker.gradle-lombok" version "1.14"
//id 'com.ewerk.gradle.plugins.auto-value' version '1.0.7'
}
ext {
queryDslVersion = '4.2.1'
lombokVersion = '1.18.10'
}
group = "com.tistory.eclipse4j"
version = "0.0.1-SNAPSHOT"
bootJar {
enabled = false
archiveVersion = '0.0.1-SNAPSHOT'
archiveExtension = 'jar'
}
jar {
enabled = true
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-configuration-processor")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
annotationProcessor("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.projectlombok:lombok:${lombokVersion}")
annotationProcessor("org.projectlombok:lombok")
compile("com.querydsl:querydsl-core:${queryDslVersion}")
compile("com.querydsl:querydsl-jpa:${queryDslVersion}")
compile("com.querydsl:querydsl-apt:${queryDslVersion}")
annotationProcessor("com.querydsl:querydsl-apt:${queryDslVersion}:jpa")
}
def querydslGenratedSrc = 'src/main/generated'
querydsl {
library = "com.querydsl:querydsl-apt"
jpa = true
querydslSourcesDir = querydslGenratedSrc
}
compileQuerydsl{
options.annotationProcessorPath = configurations.querydsl
}
configurations {
querydsl.extendsFrom compileClasspath
}
sourceSets {
main.java.srcDirs += [ querydslGenratedSrc ]
}
tasks.withType(JavaCompile) {
options.annotationProcessorGeneratedSourcesDirectory = file(querydslGenratedSrc)
}
api :
plugins {
id "org.springframework.boot" version "2.2.0.RELEASE"
id "io.spring.dependency-management" version "1.0.8.RELEASE"
id "java"
}
group = 'com.tistory.eclipse4j'
version = '0.0.1-SNAPSHOT'
apply plugin: 'org.springframework.boot'
apply plugin: "io.spring.dependency-management"
dependencies {
implementation project(":core")
// API 관련 libs
}
SpringBoot Main 클래스 생성.
#> mkdir -p {root-project}/core/src/main/java/com/tistory/eclipse4j/ && touch {root-project}/core/src/main/java/com/tistory/eclipse4j/CoreApplication.java
#> mkdir -p {root-project}/api/src/main/java/com/tistory/eclipse4j/ && touch {root-project}/api/src/main/java/com/tistory/eclipse4j/ApiApplication.java
#> vi {root-project}/core/src/main/java/com/tistory/eclipse4j/CoreApplication.java
#> vi {root-project}/api/src/main/java/com/tistory/eclipse4j/ApiApplication.java
package com.tistory.eclipse4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CoreApplication {
public static void main(String[] args) {
SpringApplication.run(CoreApplication.class, args);
}
}
package com.tistory.eclipse4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ApiApplication {
public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
}
Gradle Build
#> /gradlew clean build
BUILD SUCCESSFUL in 6s
6 actionable tasks: 4 executed, 2 up-to-date
빌드전 :
빌드 후 :